Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Certificate by hash in Store C#

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?

like image 300
Cobaia Avatar asked Jul 26 '11 13:07

Cobaia


People also ask

How do I find the hash value of a certificate?

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.

Where is certificate by thumbprint in MMC?

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.


2 Answers

var cert = store.Certificates.Find(
                                    X509FindType.FindByThumbprint,
                                    thumbprint,
                                    true
                                  ).OfType<X509Certificate>().FirstOrDefault();
like image 72
Bob Vale Avatar answered Oct 16 '22 09:10

Bob Vale


Use the Find method on the collection

store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true)
like image 25
Emond Avatar answered Oct 16 '22 08:10

Emond