Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CryptDuplicateHash (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function makes an exact copy of a hash and the state the hash is in.

A hash can be created in a piece-by-piece way. This function can create separate hashes of two different contents that begin with the same content.

BOOL WINAPI CryptDuplicateHash( 
  DWORD* pdwReserved, 
  DWORD dwFlags, 


[in] HCRYPTHASH handle to the hash to be duplicated.
[in] Reserved for future use and must be set to NULL.
[in] Reserved for future use and must be set to zero.
[out] Pointer to the HCRYPTHASH handle to the duplicated hash.

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 the GetLastError function. The error values prefaced by NTE are generated by the particular cryptographic service provider (CSP) you are using.

Value Description
ERROR_CALL_NOT_IMPLEMENTEDBecause this is a new function, existing CSPs may not implement it. This error is returned if the CSP does not support this function.
ERROR_INVALID_PARAMETEROne of the parameters contains an invalid value. This is most often an illegal pointer.
NTE_BAD_HASHThe handle to the original hash is not valid.


This function makes copies of hashes and the exact state of the hash. For example, a caller may want to generate two hashes, but both hashes have to start with common hashed data. A hash could be created, the common data hashed, a duplicate made with the CryptDuplicateHash function, and then the data unique to each hash would be hashed.

The CryptDestroyHash function must be called to destroy any hashes that are created with the CryptDuplicateHash function. Destroying the original hash does not cause the duplicate hash to be destroyed. Once a duplicate hash is made it is separate from the original hash. There is no shared state between the two hashes.

Example Code

HCRYPTHASH hOriginalHash = 0;
HCRYPTHASH hDuplicateHash = 0;
DWORD dwErr;

// Create a hash.
if (!CryptCreateHash(hProv, CALG_SHA1, 0, &hOriginalHash))
 {printf("ERROR - CryptCreateHash: %X\n", GetLastError());

// Hash common data.
if (!CryptHashData(hOriginalHash, (BYTE*)"Common Data", sizeof("Common Data"), 0))
 {printf("ERROR - CryptHashData: %X\n", GetLastError());

// Duplicate the hash.
if (!CryptDuplicateHash(hOriginalHash, NULL, 0, &hDuplicateHash))
 {printf("ERROR - CryptDuplicateHash: %X\n", GetLastError());

// Hash some data with the original hash.
if (!CryptHashData(hOriginalHash, (BYTE*)"Some Data", sizeof("Some Data"), 0))
 {printf("ERROR - CryptHashData: %X\n", GetLastError());

// Hash other data with the duplicate hash.
if (!CryptHashData(hDuplicateHash, (BYTE*)"Other Data", sizeof("Other Data"), 0))
 {printf("ERROR - CryptHashData: %X\n", GetLastError());


// Destroy the original hash.
if (!CryptDestroyHash (hOriginalHash))
 {printf("ERROR - CryptDestroyHash: %X\n", GetLastError());

// Destroy the duplicate hash.
if (!CryptDestroyHash(hDuplicateHash))
 {printf("ERROR - CryptDestroyHash: %X\n", GetLastError());


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

See Also

CryptDestroyHash | HCRYPTHASH

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.

© 2015 Microsoft