【发布时间】:2018-01-18 00:54:07
【问题描述】:
我想通过指纹在 StoreLocation.LocalMachine 中查找证书,但是,我发现如果我不指定 StoreName,我什么也得不到:
certStore = new X509Store(StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
// always find nothing, no matter runs as Administrator or not.
但是如果我在初始化X509Store时指定StoreName,我可以找到证书。
certStore = new X509Store(StoreName.TrustedPublisher, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
MSDN并没有说X509Store构造函数的区别,如果没有指定StoreName,是不是意味着它会在所有商店名称中搜索?在我看来,情况并非如此。
【问题讨论】:
标签: c# x509certificate x509 x509certificate2