Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve a certificate thumbprint in C++

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?

like image 363
user844541 Avatar asked Oct 29 '12 14:10

user844541


1 Answers

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)

like image 72
user844541 Avatar answered Oct 06 '22 01:10

user844541