简体   繁体   English

如何以编程方式获取X509证书中的电子邮件地址?

[英]How to obtain email address in X509 Certificate programmatically?

I'm trying to get both the CN and emailAddress field from a X509 cert object in C. Currently i'm getting the CN like this: 我正在尝试从C中的X509证书对象获取CN和emailAddress字段。目前,我正在像这样获取CN:

cert_entry = X509_NAME_get_entry(X509_get_subject_name(cert), 0);
ASN1_STRING *entryData = X509_NAME_ENTRY_get_data( cert_entry );
ASN1_STRING_to_UTF8(&CN, entryData);
printf("%s",CN);

My question is how do I get the emailAddress field? 我的问题是如何获取emailAddress字段? I thought about parsing the string, but I'm guess there has to be a smarter way of doing that? 我考虑过解析字符串,但是我想必须有一种更聪明的方式来做到这一点?

Figured it out 弄清楚了

X509_NAME * subject_name = X509_get_subject_name(cert); 
int nid_email = OBJ_txt2nid("emailAddress"); 
X509_NAME_get_text_by_NID(subject_name, nid_email, peer_email, 256);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM