Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CryptHashSessionKey (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function computes the cryptographic hash of a session key object. This function can be called multiple times with the same hash handle to compute the hash of multiple keys. Calls to the CryptHashSessionKey function can be interspersed with calls to the CryptHashData function.

Before calling this function, the CryptCreateHash function must be called to get a handle to a hash object.

BOOL WINAPI CryptHashSessionKey( 
  HCRYPTHASH hHash,
  HCRYPTKEY hKey, 
  DWORD dwFlags
);

Parameters

hHash
[in] HCRYPTHASH handle to the hash object created by calling the CryptCreateHash function.
hKey
[in] HCRYPTKEY handle to the key object to be hashed.
dwFlags
[in] Reserved for future use and must be set to zero.

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.

ValueDescription
ERROR_INVALID_HANDLEOne of the parameters specifies an invalid handle.
ERROR_INVALID_PARAMETEROne of the parameters contains an invalid value. This is most often an illegal pointer.
NTE_BAD_ALGIDThe hHash handle specifies an algorithm that this CSP does not support.
NTE_BAD_FLAGSThe dwFlags parameter is nonzero.
NTE_BAD_HASHThe hash object specified by the hHash parameter is invalid.
NTE_BAD_HASH_STATEAn attempt was made to add data to a hash object that is already marked as finished.
NTE_BAD_KEYA keyed hash algorithm is being used, but the session key is no longer valid. This error will be generated if the session key is destroyed before the hashing operation is complete.
NTE_BAD_UIDThe CSP context that was specified when the hash object was created cannot be found.
NTE_FAILThe function failed in some unexpected way.

Example Code

#include <wincrypt.h>

HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
HCRYPTKEY hKey = 0;

// Get a handle to the default provider using CryptAcquireContext.
// For sample code, see CryptAcquireContext.
...
...

// Create a hash object.
if(!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
 printf("Error %x during CryptBeginHash!\n", GetLastError());
 goto done;
}

// Create a random session key.
if(!CryptGenKey(hProv, CALG_RC2, CRYPT_EXPORTABLE, &hKey)) {
 printf("Error %x during CryptGenKey!\n", GetLastError());
 goto done;
}

// Compute the cryptographic hash on the key object.
if(!CryptHashSessionKey(hHash, hKey, 0)) {
 printf("Error %x during CryptHashSessionKey!\n", GetLastError());
 goto done;
}

// Use the hash of the key object. For instance, additional 
// data could be hashed and sent in a message to several recipients. 
// The recipients will be able to verify who the message originator 
// is if the key used is also exported to them..
...

done:

// Destroy the hash object.
if(hHash) CryptDestroyHash(hHash);

// Destroy the session key.
if(hKey) CryptDestroyKey(hKey);

// Free the CSP handle.
if(hProv) CryptReleaseContext(hProv,0);
 

Requirements

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

See Also

CryptCreateHash | CryptGenKey | CryptHashData


Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.