The CryptSetHashParam function, in theory, customizes the operations of a hash object. Currently, only a single parameter is defined for this function.
#include <wincrypt.h>
BOOL WINAPI CryptSetHashParam(
HCRYPTHASH hHash, // in
DWORD dwParam, // in
BYTE *pbData, // in
DWORD dwFlags // in
);
If the function succeeds, the return value is TRUE. If it fails, the return value is FALSE. To retrieve extended error information, use the GetLastError function.
The following table lists the error codes most commonly returned by the GetLastError function. The error codes prefaced by "NTE" are generated by the particular CSP you are using.
Error code | Description |
---|---|
ERROR_INVALID_HANDLE | One of the parameters specifies an invalid handle. |
ERROR_BUSY | The CSP context is currently being used by another process. |
ERROR_INVALID_PARAMETER | One of the parameters contains an invalid value. This is most often an illegal pointer. |
NTE_BAD_FLAGS | The dwFlags parameter is nonzero or the pbData buffer contains an invalid value. |
NTE_BAD_HASH | The hash object specified by the hHash parameter is invalid. |
NTE_BAD_TYPE | The dwParam parameter specifies an unknown parameter. |
NTE_BAD_UID | The CSP context that was specified when the hKey key was created cannot be found. |
NTE_FAIL | The function failed in some unexpected way. |
The dwParam parameter can be set to one of the following values:
Some CSPs will not support this capability. Occasionally, it is convenient to sign a hash value that has been generated elsewhere. This is the usual sequence of operations:
Note Some CSP types may add additional parameters that can be set with this function.
// EXAMPLE CODE FOR USING CryptSetHashParam
// Set up the variables.
HCRYPTHASH hHash; // A handle to the hash object on which to set
// parameters
DWORD dwParam; // dwParam- paramater # can be HP_HMAC_INFO-
// initialized elsewhere
BYTE pbData[16]; // The parameter data buffer
DWORD dwFlags = 0;// set to zero
BOOL Return;
Return = CryptSetHashParam(hHash, dwParam, pbData, dwFlags);
if (Return) {
cout<< "function succeeds"<< endl;
}
else {
cout<< "retrieve error"<< endl;
}
Windows NT: Requires version 4.0 or later.
Windows: Requires Windows 95 OSR2 or later (or Windows 95 with IE 3.02 or later).
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use advapi32.lib.
CryptCreateHash, CryptDestroyHash, CryptGetHashParam, CryptSetKeyParam, CryptSignHash