The CryptVerifyDetachedMessageHash function verifies a detached hash.
#include <wincrypt.h>
BOOL WINAPI CryptVerifyDetachedMessageHash(
PCRYPT_HASH_MESSAGE_PARA pHashPara, // in
BYTE *pbDetachedHashBlob, // in
DWORD cbDetachedHashBlob, // in
DWORD cToBeHashed, // in
const BYTE *rgpbToBeHashed[ ], // in
DWORD rgcbToBeHashed[ ], // in
BYTE *pbComputedHash, // out, optional
DWORD *pcbComputedHash // in/out, optional
);
This parameter can be NULL if the newly created hash is not needed for additional processing, or to set the size of the hash for memory allocation purposes. For more information, see Common In/Out Parameter Conventions.
Note that when processing the data returned in the buffer, applications need to use the actual size of the data returned. The actual size may be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to insure that the largest possible output data will fit in the buffer.) On output, the variable pointed to by this parameter is updated to reflect the actual size of the data copied to the buffer.
TRUE if the function succeeded and the detached hash was verified. FALSE if the function failed.
Call GetLastError to see the reason for any failures. Note that errors from the called functions CryptCreateHash, CryptHashData, and CryptGetHashParam may be propagated to this function. This function has the following error codes.
Error code | Description |
---|---|
CRYPT_E_OSS_ERROR | Message ASN.1 decoding error. Note, to get the OSS error subtract CRYPT_E_OSS_ERROR from the returned error and see asn1code.h for details on the error. |
CRYPT_E_UNEXPECTED_MSG_TYPE | Not a hashed cryptographic message. |
E_INVALIDARG | Invalid message encoding type. Currently only PKCS_7_ASN_ENCODING is supported. Invalid cbSize in *pHashPara. |
ERROR_MORE_DATA | If the buffer specified by the pbComputedHash parameter is not large enough to hold the returned data, the function sets the ERROR_MORE_DATA code, and stores the required buffer size, in bytes, into the variable pointed to by pcbComputedHash. |
// EXAMPLE CODE FOR USING CryptVerifyDetachedMessageHash() to verify a
// single detached hash. The computed hash is not needed and
// will not be returned.
// Assume that the application already knows the address of the
// target detached hash (pbDetachedHashBlob) and its size
// (cbDetachedHashBlob), the address of the content to be hashed for
// comparison (rgpbToBeHashed[]), the number of elements in the array
// (cToBeHashed), and the size of each of the elements
// (rgcbToBeHashed[]).
// Set up the variables.
CRYPT_HASH_MESSAGE_PARA HashPara; // Struct initialized elsewhere
BYTE* pbDetachedHashBlob; // Initialized elsewhere
DWORD cbDetachedHashBlob; // Initialized elsewhere
DWORD cToBeHashed = 1;
const BYTE* rgpbToBeHashed[1]; // Initialized elsewhere
DWORD rgcbToBeHashed[1]; // Initialized elsewhere
BOOL fReturn = FALSE;
// Call CryptVerifyDetachedMessageHash to verify the detached hash.
fReturn = CryptVerifyDetachedMessageHash(&HashPara,
pbDetachedHashBlob, cbDetachedHashBlob,
cToBeHashed, rgpbToBeHashed,rgcbToBeHashed,
NULL, NULL);
if(fReturn != TRUE)
;// The hash was not verified. Handle the condition.
// If the function succeeded, the detached hash was verified.
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.