简体   繁体   English

使用C#从证书签名请求(CSR)中读取电子邮件字段

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

I'm using the following code to read the attributes of a CSR: 我正在使用以下代码来读取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 在attribs我得到共同的名称,组织,部门,城市,国家,但不是电子邮件地址

Shouldn't be mandatory for a CSR? CSR不应该是强制性的吗? Is there a way to read it with C#? 有没有办法用C#读取它?

in attribs I get common name, organization, department 在attribs我得到共同的名字,组织,部门

you are going in the right direction, but it appears that email RDN attribute is not presented in the subject field. 您正朝着正确的方向前进,但似乎电子邮件RDN属性未显示在主题字段中。

Shouldn't be mandatory for a CSR? 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. 因此,如果主题字符串中缺少E=Email=属性,则此属性不会显示在那里。

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

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