CryptCreateHash (Windows CE 5.0)

Send Feedback

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.



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

  • Algid
    [in] ALG_ID identifier of the hash algorithm. The valid value for this parameter varies depending on the CSP. Common hash algorithm identifiers are: CALG_MD2, CALG_MD5, CALG_SHA, CALG_SHA1, CALG_SHA_256, CALG_SHA_384, CALG_SHA_512, CALG_MAC, CALG_HMAC, and CALG_SSL3_SHAMD5. See ALG_ID for definitions.

  • 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.


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.


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

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.