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.