How to get Certificate by hash in Windows Store using C#?
sha1 example:7a0b021806bffdb826205dac094030f8045d4daa
this loop works but:
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 mCert in store.Certificates)
{
Console.WriteLine( mCert.Thumbprint);
}
store.Close();
Is there a direct method?
To look up an existing certificate, simply bring up the IIS Management Console, go to the Machine node, then Server Certificates: You can see the certificate hash in the rightmost column. You can also double click and open the certificate and go in the Details of the certificate.
Right-click Certificates (Local Computer) in MMC > Find Certificates, and pick the hash algorithm under Look in Field, with the thumbprint in the Contains box.
var cert = store.Certificates.Find(
X509FindType.FindByThumbprint,
thumbprint,
true
).OfType<X509Certificate>().FirstOrDefault();
Use the Find method on the collection
store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With