CryptHashData function (wincrypt.h)

Important  This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.
The CryptHashData function adds data to a specified hash object. This function and CryptHashSessionKey can be called multiple times to compute the hash of long or discontinuous data streams.

Before calling this function, CryptCreateHash must be called to create a handle of a hash object.


BOOL CryptHashData(
  [in] HCRYPTHASH hHash,
  [in] const BYTE *pbData,
  [in] DWORD      dwDataLen,
  [in] DWORD      dwFlags


[in] hHash

Handle of the hash object.

[in] pbData

A pointer to a buffer that contains the data to be added to the hash object.

[in] dwDataLen

Number of bytes of data to be added. This must be zero if the CRYPT_USERDATA flag is set.

[in] dwFlags

The following flag values are defined.

Value Meaning
This flag is not used.
1 (0x1)
All Microsoft Cryptographic Providers ignore this parameter. For any CSP that does not ignore this parameter, if this flag is set, the CSP prompts the user to input data directly. This data is added to the hash. The application is not allowed access to the data. This flag can be used to allow the user to enter a PIN into the system.

Return value

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. For extended error information, call GetLastError.

The error codes prefaced by "NTE" are generated by the particular CSP you are using. Some possible error codes follow.

Return code Description
One of the parameters specifies a handle that is not valid.
One of the parameters contains a value that is not valid. This is most often a pointer that is not valid.
The hHash handle specifies an algorithm that this CSP does not support.
The dwFlags parameter contains a value that is not valid.
The hash object specified by the hHash parameter is not valid.
An attempt was made to add data to a hash object that is already marked "finished."
A keyed hash algorithm is being used, but the session key is no longer valid. This error is generated if the session key is destroyed before the hashing operation is complete.
The CSP does not ignore the CRYPT_USERDATA flag, the flag is set, and the dwDataLen parameter has a nonzero value.
The CSP context that was specified when the hash object was created cannot be found.
The function failed in some unexpected way.
The CSP ran out of memory during the operation.


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header wincrypt.h
Library Advapi32.lib
DLL Advapi32.dll

See also




Hash and Digital Signature Functions