简体   繁体   中英

Reading email field from a certificate signing request (CSR) with C#

I'm using the following code to read the attributes of a CSR:

string csr = myCSR;
CX509CertificateRequestPkcs10 request = new CX509CertificateRequestPkcs10();
request.InitializeDecode(csr, EncodingType.XCN_CRYPT_STRING_BASE64_ANY);
request.CheckSignature();
string tmp = ReadDnsSan(request);
string attribs = (((CX500DistinguishedName)request.Subject).Name);

in attribs I get common name, organization, department, city, country, but not the email address

Shouldn't be mandatory for a CSR? Is there a way to read it with C#?

in attribs I get common name, organization, department

you are going in the right direction, but it appears that email RDN attribute is not presented in the subject field.

Shouldn't be mandatory for a CSR?

no. Moreover, entire Subject field is optional. Therefore, you may need to modify your code accordingly. There might be a situation when Subject field is empty, then subject information shall be presented in the Subject Alternative Names extension.

Therefore, if E= or Email= attributes are missing from the subject string, then this attribute is not presented there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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