Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CryptCreateHash

Windows Mobile 6.5
A version of this page is also available for
4/8/2010

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( 
  HCRYPTPROV hProv,
  ALG_ID Algid, 
  HCRYPTKEY hKey, 
  DWORD dwFlags, 
  HCRYPTHASH* phHash
);

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.

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.

Headerwincrypt.h
Librarycoredll.lib
Windows Embedded CEWindows CE 2.10 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

Show:
© 2015 Microsoft