The CryptMsgGetAndVerifySigner function gets and verifies the signer of a cryptographic message.
#include <wincrypt.h>
BOOL WINAPI CryptMsgGetAndVerifySigner(
HCRYPTMSG hCryptMsg, // in
DWORD cSignerStore, // in
HCERTSTORE *rghSignerStore, // in, optional
DWORD dwFlags, // in
PCCERT_CONTEXT *ppSigner, // out, optional
DWORD pdwSignerIndex // in/out, optional
);
The CMSG_SIGNER_ONLY_FLAG can be set to return the signer without doing the signature verification.
If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified by *pdwSignerIndex. Otherwise, iterate through all the signers until a signer verifies or until there are no more signers.
If the function fails, the return value is FALSE (zero). If it succeeds, the return value is TRUE (non-zero).
To retrieve extended error information, use the GetLastError function.
For a verified signature, *ppSigner is updated with the certificate context of the signer and *pdwSignerIndex is updated with the index of the signer. ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't interested in getting the certificate context and/or index of the signer.
// EXAMPLE CODE FOR USING CryptMsgGetAndVerifySigner().
// Gets and verifies the cryptographic message.
// Assume that the handle to the crypt message (hCryptMsg)
// and the pointer to the array of signer stores
// (rghSignerStore) have already been defined.
// Set up the variables.
HCRYPTMSG hCryptMsg; // A handle to the crypt message
DWORD cSignerStore = 128; // # of stores in SignerStore
HCERTSTORE *rghSignerStore; // Array of signer rghstores
DWORD dwFlags = CMSG_TRUSTED_SIGNER_FLAG;
// Flag value
PCCERT_CONTEXT *ppSigner = NULL; // Pointer to a certificate context pointer
DWORD *pdwSignerIndex; // Pointer to the signer index
BOOL fResult; // Return TRUE if function succeeds
// FALSE if function fails
// Function call to get and verify the signer
// of a cryptographic message
fResult= CryptMsgGetAndVerifySigner(
hCryptMsg, // in
cSignerStore, // in
rghSignerStore, // in
dwFlags, // in
ppSigner, // out
pdwSignerIndex = NULL);
// in/out or set to NULL to indicate no
// interest in getting signer index
if (!fResult){
cout<< "Call to CryptMsgGetAndVerifySigner failed"<< endl
<< "error code = "<< GetLastError()<< endl;
}
else {
cout<< "Call to CryptMsgGetAndVerifySigner successful"<< endl
<< "Flag value = "<< dwFlags<< endl
<< "Pointer to the signer of certificate context = "<< &ppSigner<< endl
<< "Index of the signer = "<< &pdwSignerIndex<< endl;
}
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
CERT_CONTEXT, CTL_CONTEXT, CryptMsgOpenToDecode, CryptMsgControl