5

I am developing a C++ application, and I need to check the thumbprint of a certificate.

I found this solution check for a specific signature, using CryptQueryObject(). but I still can't find a way to retrieve the Thumprint.

In C# I can use the method GetCertHashString to get the hash (which is what I need) or use the property X509Certificate.Thumbprint

I know I need to get the hash value of the public key, but I don't know how to retrieve the public key..

How do I do that in C++? is there a method for that?

Community
  • 1
  • 1
user844541
  • 2,748
  • 4
  • 30
  • 55

1 Answers1

12

Found how to do it.

you should use CryptHashCertificate

Like that:

DWORD* thumbPrintSize;
BYTE* thumbPrint;   
if (!CryptHashCertificate(0, hashAlg, 0,pCertContext->pbCertEncoded,
     pCertContext->cbCertEncoded, thumbPrint, thumbPrintSize)) {
        return false;
}

Where pCertContext is the certificate, and hashAlg is the hashing algorithm (usually sha-1)

user844541
  • 2,748
  • 4
  • 30
  • 55
  • Does it calculate or retrieve it from certificate? – Mustafa Chelik Dec 18 '16 at 21:30
  • 1
    @MustafaChelik It calculates the thumbprint, because the thumbprint is not stored in the certificate. – X. Liu May 10 '17 at 21:20
  • CryptHashCertificate is deprecated, however CryptHashCertificate2 is pretty similar. However, my thumbprint doesn't seem to match the thumbprint seen using the DigitalSignature tab in properties. – NiteRain Feb 09 '18 at 16:37