gpt4 book ai didi

c# - 枚举证书问题 (X509Certificate2)

转载 作者:行者123 更新时间:2023-11-30 15:40:34 25 4
gpt4 key购买 nike

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

string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority",     "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
for (int x = 0; x < stores.Length; x++)
{
X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

store.Open(OpenFlags.ReadOnly);

foreach (X509Certificate2 mCert in store.Certificates)
{
//handle certificates
}

}

最佳答案

我最终让它开始工作,出于某种原因,对于除“CertificateAuthority”之外的每个商店,您都可以像我在原始代码 (stores[x]) 中那样传递名称。对于“CertificateAuthority”,我必须明确传递“Store.CertificateAuthority”。我觉得这是 X509Store 类中的错误。

//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);

关于c# - 枚举证书问题 (X509Certificate2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9068807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com