The CryptCreateHash function is used to initiate the hashing of a stream of data. It returns to the caller a handle to a CSP hash object.
Declare Function CryptCreateHash Lib "advapi32.dll" (ByVal hProv As Long, ByVal Algid As Long, ByVal hKey As Long, ByVal dwFlags As Long, phHash As Long) As Long
|Operating Systems Supported|
|Windows NT 4.0 or later; Windows 95 OSR2 or later (or Windows 95 with Internet Explorer 3.02 or later)|
[in] A handle to the CSP to use. An application obtains this handle using the CryptAcquireContext function.
[in] An algorithm identifier of the hash algorithm to use.
The valid values for this parameter will vary, depending on the CSP that is used. See the “Remarks” section for the list of default algorithms.
[in] If the type of hash algorithm is a keyed hash, such as a MAC algorithm, the key for the hash should be passed in this parameter. For nonkeyed algorithms, this parameter should be set to zero.
The key must be to a block cipher, such as RC2, with a cipher mode of CBC.
[in] The flag values. This parameter is reserved for future use and should always be zero.
[out] The address to which the function copies a handle to the new hash object.
The Microsoft Base Cryptographic Provider defines the following hashing algorithms.
CALG_HMAC HMAC: a keyed hash algorithm
CALG_MAC: Message Authentication Code
CALG_SHA: US DSA Secure Hash Algorithm
CALG_SHA1: Same as CALG_SHA
CALG_SSL3_SHAMD5: SSL3 client authentication
|If the function succeeds, the return value is nonzero. |
If the function fails, the return value is zero. 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.
One of the parameters specifies an invalid handle.
One of the parameters contains an invalid value. This is most often an illegal pointer.
The operating system ran out of memory during the operation.
The Algid parameter specifies an algorithm that this CSP does not support.
The dwFlags parameter is nonzero.
A keyed hash algorithm (such as CALG_MAC) is specified by Algid and the hKey parameter is either zero or it specifies an invalid key handle. This error code will also be returned if the key is to a stream cipher, or if the cipher mode is anything other than CBC.
The CSP ran out of memory during the operation.