C# 枚举证书颁发(X509Certificate2)

C# 枚举证书颁发(X509Certificate2),c#,C#,我正在尝试枚举服务器上的证书存储,并获取有关每个证书的信息。代码正常工作,但缺少“中间证书颁发机构”存储中找到的所有证书 string[]stores=新字符串[]{“AddressBook”、“AuthRoot”、“CertificateAuthority”、“Disallowed”、“My”、“Root”、“TrustedPeople”、“TrustedPublisher”}; 对于(int x=0;x

我正在尝试枚举服务器上的证书存储,并获取有关每个证书的信息。代码正常工作,但缺少“中间证书颁发机构”存储中找到的所有证书

string[]stores=新字符串[]{“AddressBook”、“AuthRoot”、“CertificateAuthority”、“Disallowed”、“My”、“Root”、“TrustedPeople”、“TrustedPublisher”};
对于(int x=0;x
我最终让它工作了,出于某种原因,除了“CertificateAuthority”之外,每个商店都可以像我在原始代码(stores[x])中那样传递名称。对于“CertificateAuthority”,我必须明确通过“Store.CertificateAuthority”。我觉得这是X509Store类中的一个bug

//Old Code
string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority" "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

//New Code
 X509Store store2= new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);
对于中间CA存储,请使用“CA”而不是“CertificateAuthority”。 在MSDN中,它只列出了存储名称的枚举,但它们并不是真正适合您传入的字符串。
找到正确的存储名称字符串的一种方法是首先使用StoreName枚举打开一个存储,然后检查store.name值。

对于“中间证书颁发机构”,store.Certificates集合是否为空?
//Old Code
string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority" "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

//New Code
 X509Store store2= new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);