简体   繁体   English

如何从X509Certificate2获取RFC-1779中的颁发者名称?

[英]How to get issuer name in RFC-1779 from X509Certificate2?

The Issuer property from X509Certificate2 returns a string such as: X509Certificate2Issuer属性返回一个string例如:

"CN=eBusiness Development CA, OU=ITSB eBusiness Systems Team, O=AVANO, L=Sydney, S=NSW, C=AU" “ CN =电子商务开发CA,OU = ITSB电子商务系统团队,O = AVANO,L =悉尼,S = NSW,C = AU”

How do I get the same in RFC-1779? 如何在RFC-1779中获得相同的信息? For example: 例如:

"/C=AU/ST=NSW/L=Sydney/O=AVANO/OU=ITSB eBusiness Systems Team/CN=eBusiness Development CA" “ / C = AU / ST = NSW / L =悉尼/ O = AVANO / OU = ITSB电子商务系统团队/ CN =电子商务开发CA”

var cert = new X509Certificate2(certPath, password);
Console.WriteLine(cert.Issuer);

The string you're wanting is just the reverse of the string you're actually getting from Issuer , and is delimited by slashes instead of commas with a following space. 您想要的字符串与您实际从Issuer获得的字符串相反,并且由斜杠而不是逗号分隔,并带有空格。

My first attempt to solve this problem was to create a new X500DistinguishedName object, passing the certificate's IssuerName and X500DistinguishedNameFlags.Reversed to the constructor: 解决这个问题的X500DistinguishedName是创建一个新的X500DistinguishedName对象,将证书的IssuerNameX500DistinguishedNameFlags.Reversed传递给构造函数:

var distinguishedName = new X500DistinguishedName(cert.Issuer, X500DistinguishedNameFlags.Reversed);

But that didn't provide me with the result I was hoping for. 但这并没有给我带来我所希望的结果。 I'm not sure of any baked in way to do this. 我不确定是否有任何方法可以做到这一点。 But you could try reformatting the string manually to meet your needs: 但是您可以尝试手动重新格式化字符串以满足您的需求:

var split = cert.Issuer.Split(new []{',', ' '}, StringSplitOptions.RemoveEmptyEntries);
var reversed = split.Reverse();
var finalIssuerName = string.Join("/", reversed); 

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

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