CryptGetHashParam (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function retrieves data that governs the operations of a hash object and retrieves the actual hash value.

BOOL CRYPTFUNC CryptGethashParam( 
  DWORD dwParam, 
  BYTE* pbData, 
  DWORD* pdwDataLen, 
  DWORD dwFlags


[in] HCRYPTHASH handle to the hash object to query.
[in] Specifies the query type. The following table shows the available query types. Cryptographic service providers (CSPs) can add values to the list.
Query typeDescriptionpbData content
HP_ALGIDHash algorithmALG_ID identifier for the algorithm specified when the hash object was created. For a list of hash algorithms, see CryptCreateHash.
HP_HASHSIZEHash value sizeDWORD value indicating the number of bytes in the hash value. This is usually 16 to 20, depending on the hash algorithm. Applications must retrieve this value just before the HP_HASHVAL value so the correct amount of memory can be allocated.
HP_HASHVALHash valueThe hash value or message hash for the hash object specified by hHash. This value is generated based on the data supplied to the hash object earlier through the CryptHashData and CryptHashSessionKey functions.

The CryptGetHashParam function completes the hash. After CryptGetHashParam is called, data cannot be added to the hash. Additional calls to CryptHashData or CryptHashSessionKey fail. After the application is done with the hash, CryptDestroyHash should be called to destroy the hash object.

[out] Pointer to a buffer that receives the specified parameter data. The form of this data varies depending on the dwParam query type. This parameter can be NULL to set the size of this buffer for memory allocation purposes.
[in, out] On input, pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the pbData parameter. On output, the variable pointed to by the pdwDataLen parameter contains the number of bytes stored in the buffer.

When processing the data returned in the buffer, applications must 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 ensure 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.

[in] Reserved for future use and must be set to zero.

Return Values

TRUE indicates success. FALSE indicates failure. To get extended error information, call the GetLastError function.

The following table shows the common values for GetLastError function. The error values prefaced by NTE are generated by the particular CSP you are using.

ERROR_INVALID_HANDLEOne of the parameters specifies an invalid handle.
ERROR_INVALID_PARAMETEROne of the parameters contains an invalid value. This is most often an illegal pointer.
ERROR_MORE_DATAIf the buffer specified by the pbData 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 pdwDataLen.
NTE_BAD_FLAGSThe dwFlags parameter is nonzero.
NTE_BAD_HASHThe hash object specified by the hHash parameter is invalid.
NTE_BAD_TYPEThe dwParam parameter specifies an unknown parameter number.
NTE_BAD_UIDThe CSP context that was specified when the hash was created cannot be found.

Example Code

#include <wincrypt.h>

BYTE *pbHash = NULL;
DWORD dwHashLen;
#define BUFFER_SIZE 256
DWORD dwCount;

// Get a handle to the default provider using CryptAcquireContext.
// For sample code, see CryptAcquireContext.
// Create a hash object.
if(!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
 printf("Error %x during CryptBeginHash!\n", GetLastError());
 goto done;

// Fill the buffer with test data.
for(i = 0 ; i < BUFFER_SIZE ; i++) {
 pbBuffer[i] = (BYTE)i;

// Put the hash in buffer.
if(!CryptHashData(hHash, pbBuffer, BUFFER_SIZE, 0)) {
 printf("Error %x during CryptHashData!\n", GetLastError());
 goto done;

// Read the hash value size and allocate memory.
dwCount = sizeof(DWORD);
if(!CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE *)&dwHashLen, 
 &dwCount, 0)) {
 printf("Error %x during reading hash size!\n", GetLastError());
 goto done;
if((pbHash = malloc(dwHashLen)) == NULL) {
 printf("Out of memory!\n");
 goto done;

// Read the hash value.
if(!CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &dwHashLen, 0)) {
 printf("Error %x during reading hash value!\n", GetLastError());
 goto done;

// Print the hash value.
for(i = 0 ; i < dwHashLen ; i++) {
 printf("%2.2x ",pbHash[i]);


// Free memory.
if(pbHash !=NULL) free(pbHash);

// Destroy the hash object.
if(hHash) CryptDestroyHash(hHash);
// Free the CSP handle.
if(hProv) CryptReleaseContext(hProv,0);


OS Versions: Windows CE 2.10 and later.
Header: Wincrypt.h.
Link Library: Coredll.lib.

See Also

CryptCreateHash | CryptGetKeyParam | CryptHashData | CryptHashSessionKey | CryptSetHashParam | ALG_ID

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.