Export (0) Print
Expand All
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.

CryptDuplicateHash

Windows CE 3.0

This function is used to make an exact copy of a hash and the state the hash is in.

BOOL WINAPI CryptDuplicateHash( 
HCRYPTHASH hHash,
DWORD *pdwReserved, 
DWORD dwFlags, 
HCRYPTHASH phHash);

Parameters

hHash
[in] Handle to the hash to be duplicated.
pdwReserved
[in] Reserved for future use; set to NULL.
dwFlags
[in] Specifies a bitmask of flags. This parameter is reserved for future use; set to 0.
phHash
[out] Pointer to the handle to the duplicated hash.

Return Values

TRUE indicates success. FALSE indicates failure. To get extended error information, call GetLastError. Common values for GetLastError are described in the following table. The error values prefaced by "NTE" are generated by the particular CSP you are using.

Value Description
ERROR_CALL_NOT_IMPLEMENTED Since 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_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.
NTE_BAD_HASH The handle to the original hash is not valid.

Remarks

CryptDuplicateHash is used to make copies of hashes and the exact state of the hash. An example of how this function might be used is that a caller may want to generate two hashes, but both hashes have to start with some common data hashed. 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.

CryptDestroyHash must be called to destroy any hashes that are created with CryptDuplicateHash. 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

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

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

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

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

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

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

...

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

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

Requirements

Runs On Versions Defined in Include Link to
Windows CE OS 2.10 and later Wincrypt.h   Cryptapi.lib
Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

CryptDestroyHash


 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.

Show:
© 2014 Microsoft