CryptCreateHash

This function initiates the hashing of a stream of data. It creates and returns to the calling application a handle to a cryptographic service provider (CSP) hash object. This handle is used in subsequent calls to the CryptHashData function and CryptHashSessionKey function to hash streams of data and session keys.

BOOL CRYPTFUNC CryptCreateHash(HCRYPTPROVhProv,ALG_IDAlgid,HCRYPTKEYhKey,DWORDdwFlags,HCRYPTHASH* phHash);

Parameters

  • hProv
    [in] HCRYPTPROV handle to a CSP created by a call to the CryptAcquireContext function.

  • Algid
    [in] ALG_ID structure containing the identifier and necessary additional parameters of the hash algorithm.

    The valid value for this parameter varies depending on the CSP. See the Remarks section for a list of default algorithms.

  • hKey
    [in] HCRYPTKEY handle to the key.

    If the type of hash algorithm is a keyed hash, such as the HMAC or MAC algorithm, the key for the hash should be passed in this parameter. For nonkeyed algorithms, this parameter must be set to zero.

    For keyed algorithms, the key must be to a block cipher, such as RC2, that has a cipher mode of CBC.

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

  • phHash
    [out] Pointer to a handle to the new hash object.

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. The error values prefaced by NTE are generated by the particular CSP you are using.

Value Description
ERROR_INVALID_HANDLE One of the parameters specifies an invalid handle.
ERROR_INVALID_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.
ERROR_NOT_ENOUGH_MEMORY The operating system ran out of memory during the operation.
NTE_BAD_ALGID The Algid parameter specifies an algorithm that this CSP does not support.
NTE_BAD_FLAGS The dwFlags parameter is nonzero.
NTE_BAD_KEY 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 is also returned if the key is for a stream cipher or if the cipher mode is anything other than CBC.
NTE_NO_MEMORY The CSP ran out of memory during the operation.

Remarks

The following table shows various algorithms defined in the Wincrypt.h file.

Algorithm Identifier description
CALG_MD2 MD2 hashing algorithm
CALG_MD5 MD5 hashing algorithm
CALG_SHA SHA hashing algorithm
CALG_SHA1 Same as CALG_SHA
CALG_MAC MAC keyed-hash algorithm
CALG_HMAC MAC keyed-hash algorithm
CALG_SSL3_SHAMD5 SLL3 client authentication algorithm

The computation of the hash is done with the CryptHashData and CryptHashSessionKey functions. These functions require a handle to the hash object. After all the data has been added to the hash object, any of the following functions can be called:

After one of the functions from this list has been called, the CryptHashData and CryptHashSessionKey functions may not be called.

Example Code

See CryptHashSessionKey.

Requirements

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

See Also

CryptAcquireContext | CryptDeriveKey | CryptDestroyHash | CryptGetHashParam | CryptHashData | CryptHashSessionKey | CryptSignHash | CryptVerifySignature | ALG_ID | HCRYPTKEY | HCRYPTPROV

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.