如何检索您的X509Store所有证书 [英] How to retrieve all certificates in your X509Store

查看:1145
本文介绍了如何检索您的X509Store所有证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码从一个asp.net web应用检索在我的电脑中的所有证书。该证书的收藏是空的,我不明白为什么。



我试图模仿我自己的用户帐户,我没有成功也是如此。什么?我做错了。



  VAR店=新的X509Store(StoreLocation.CurrentUser); //StoreLocation.LocalMachine失败过
无功证书= store.Certificates;
的foreach(以证书VAR证书)
{
变种的friendlyName = certificate.FriendlyName;
Console.WriteLine(的friendlyName);
}

//原来的问题:它的主题名称
X509Certificate2 clientCertificate = CertificateUtility.GetCertificate(StoreName.My,StoreLocation.CurrentUser,CN = MYPC获取一个证书。域名); //返回null :(


解决方案

添加此行代码到第二行,看看它是如何工作的:

  store.Open(OpenFlags.ReadOnly); 

和那么这个底部:):

  store.Close(); 


I am using the following code to retrieve all certificates in my PC from an asp.net webapp. The certificates collection is empty, and I can't understand why.

I tried impersonating my own user account and I didn't succeed as well. What am I doing wrong?

var store = new X509Store(StoreLocation.CurrentUser); //StoreLocation.LocalMachine fails too
var certificates = store.Certificates;
foreach (var certificate in certificates)
{
    var friendlyName = certificate.FriendlyName;
    Console.WriteLine(friendlyName);
}

//original problem: fetch a single certificate by its subject name
X509Certificate2 clientCertificate = CertificateUtility.GetCertificate(StoreName.My, StoreLocation.CurrentUser,  "CN=mypc.domainname"); //returns null :(

解决方案

Add this line of code to the second line and see how it works:

store.Open(OpenFlags.ReadOnly);

and then this at the bottom :):

store.Close();

这篇关于如何检索您的X509Store所有证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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