如何使用C#在Windows应用商店中通过哈希获取证书?
sha1示例:7a0b021806bffdb826205dac094030f8045d4daa
这个循环有效但是:
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 mCert in store.Certificates)
{
Console.WriteLine( mCert.Thumbprint);
}
store.Close();
有直接方法吗?
答案 0 :(得分:24)
var cert = store.Certificates.Find(
X509FindType.FindByThumbprint,
thumbprint,
true
).OfType<X509Certificate>().FirstOrDefault();
答案 1 :(得分:2)
使用Find method on the collection
store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true)