Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Find a Certificate by Certificate Hash or Thumbprint - C#

RSS
Modified on Sat, Mar 18, 2017, 7:41 PM by Administrator Categorized as Uncategorized


private X509Certificate2 GetCertificateByHash(byte[] certHash)
{
    X509Certificate2 result = null;

    using (var certStore = new X509Store(StoreLocation.LocalMachine))
    {
        certStore.Open(OpenFlags.ReadOnly);

        var thumbprint = string.Join("", certHash.Select(a => string.Format("{0:X}", a).PadLeft(2, '0')));

        var certs = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

        if (certs.Count > 0)
        {
            result = certs[0];
        }

        certStore.Close();
    }

    return result;
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.