CryptoSys PKI Toolkit Manual

X509_CertThumb

X509_CertThumb calculates the thumbprint (message digest hash) of an X.509 certificate.

VB6/VBA Syntax

Public Declare Function X509_CertThumb Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strHexHash As String, ByVal nHexHashLen As Long, ByVal nOptions As Long) As Long

nRet = X509_CertThumb(strCertFile, strHexHash, nHexHashLen, nOptions)

Parameters

strCertFile
[in] String with the filename of the X.509 certificate (or base64 representation).
strHexHash
[out] String to receive the message digest.
nHexHashLen
[in] Long specifying the maximum length of the digest string.
nOptions
[in] Long Option flags. Select one of:
PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
PKI_HASH_MD5 to use the MD5 algorithm
PKI_HASH_MD2 to use the MD2 algorithm
PKI_HASH_SHA256) to use the SHA-256 algorithm
PKI_HASH_SHA384 to use the SHA-384 algorithm
PKI_HASH_SHA512 to use the SHA-512 algorithm
PKI_HASH_SHA224 to use the SHA-224 algorithm

C/C++ Syntax

long _stdcall X509_CertThumb(const char *szCertFile, char *szHash, long nHashLen, long flags);

Returns (VB6/C)

Long: the number of digits set in the output string or a negative error code.

.NET Equivalent

X509.CertThumb Method

Remarks

The maximum length of the digest string is PKI_MAX_HASH_CHARS characters, depending on the algorithm. C/C++ users should allocate one extra for the terminating NUL character. The default hash algorithm is SHA-1 and the result should match the SHA-1 thumbprint shown in the Windows Certificate Viewer.

Example

These examples compute the SHA-1 message digest hash ("thumbprint") of Alice's certificate from S/MIME examples.

Dim nRet As Long
Dim strCertName As String
Dim strHexHash As String
 
strHexHash = String(PKI_SHA1_CHARS, " ")
strCertName = "C:\Test\AliceRSASignByCarl.cer"
nRet = X509_CertThumb(strCertName, strHexHash, Len(strHexHash), 0)
Debug.Print "X509_CertThumb returns " & nRet & " for " & strCertName
Debug.Print strHexHash

In C:

long lRet;
char *certname = "C:\\test\\AliceRSASignByCarl.cer";
char hexdigest[PKI_SHA1_CHARS+1]; /* NB one extra */

lRet = X509_CertThumb(certname, hexdigest, sizeof(hexdigest)-1, 0);
printf("X509_CertThumb returns %ld for %s\n", lRet, certname);
printf("%s\n", hexdigest);

Both of these should result in

X509_CertThumb returns 40 for C:\Test\AliceRSASignByCarl.cer
b30c48855055c2e64ce3196492d4b83831a6b3cb

See Also

X509_CertIsValidNow X509_VerifyCert

[Contents] [Index]

[HOME]   [NEXT: X509_GetCertFromP7Chain...]

Copyright © 2004-9 D.I. Management Services Pty Ltd. All rights reserved.