我正在尝试列出计算机上的所有证书。我已经阅读了网上遇到的所有例子,但没有任何效果。我在Windows 7和Windows 8计算机上都试过没有任何错误。以下是我到目前为止的情况:
public void Analyser_Load(object sender, EventArgs e)
{
var store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates;
foreach (var certificate in certificates)
{
var friendlyName = certificate.FriendlyName;
var xname = certificate.GetName(); //obsolete
Console.WriteLine(friendlyName);
}
store.Close();
}
答案 0 :(得分:0)
尝试这样,
X509Store store = new X509Store("My");
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 mCert in store.Certificates){
//TODO's
}
答案 1 :(得分:0)
根据ILSpy,X509Store
类构造函数默认为StoreName.My
,如果您没有指定它。您的个人证书店是空的吗?
为避免歧义,我建议您始终指定商店名称和位置,例如
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);