【发布时间】:2011-09-21 01:17:44
【问题描述】:
如果 PKI 最终用户证书安装在用户 Windows 密钥库(个人)中,是否有任何方法可以检查 C#? (例外会做吗?)我会传递一些属性,比如 Name。
【问题讨论】:
标签: c# certificate keystore
如果 PKI 最终用户证书安装在用户 Windows 密钥库(个人)中,是否有任何方法可以检查 C#? (例外会做吗?)我会传递一些属性,比如 Name。
【问题讨论】:
标签: c# certificate keystore
您可以使用X509Store 类在系统上搜索证书。下面的代码示例在当前用户的个人存储中查找主题名称为“XYZ”的证书。
System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly); // Dont forget. otherwise u will get an exception.
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName,"XYZ",true);
if(certs.Count > 0)
{
// Certificate is found.
}
else
{
// No Certificate found by that subject name.
}
【讨论】: