枚举证书发行(X509Certificate2)

编程入门 行业动态 更新时间:2024-10-23 09:20:59
本文介绍了枚举证书发行(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)

本文发布于:2023-11-05 08:25:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:证书

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!