枚举证书发行(X509Certificate2) [英] Enumerating Certificates Issue (X509Certificate2)

查看:88
本文介绍了枚举证书发行(X509Certificate2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to enumerate certificate stores on my server and get information about each certificate. The code works correctly except it is missing all certificates found in the "Intermediate Certification Authorities" store.

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"之外,每个商店都可以使用,您可以像在原始代码中那样传递名称(商店[x]).对于"CertificateAuthority",我必须显式传递"Store.CertificateAuthority".

I ended up getting it to work, for some reason for every store except "CertificateAuthority" you can pass the name as done in my original code (stores[x]). For "CertificateAuthority" I had to explicitly pass "Store.CertificateAuthority".

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


这篇关于枚举证书发行(X509Certificate2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆