CPDestroyKey

The CPDestroyKey function releases the handle referenced by the hKey parameter. After a key handle has been released, it becomes invalid and cannot be used again.

BOOL CPDestroyKey(
  HCRYPTPROV hProv,  // in
  HCRYPTKEY hKey     // in
):
 

Parameters

hProv
Handle to a particular key container (or "context") within the CSP. This handle is obtained via a call to CPAcquireContext.
hKey
Handle to the key to be destroyed.

Return Values

If the function succeeds, TRUE should be returned; otherwise, return FALSE. When FALSE is returned, the appropriate error code (see the following table) must be set via SetLastError.

Error Description
NTE_BAD_KEY The hKey parameter does not contain a valid handle to a key.
NTE_BAD_UID The hProv parameter does not contain a valid context handle.

Remarks

If the handle refers to a session key, or to a public key that has been imported into the CSP via CryptImportKey, this function destroys the key and frees the memory that the key occupied. The CSP will typically scrub the memory where the key was held before freeing it.

On the other hand, if the handle refers to a public/private key pair (obtained from CryptGetUserKey), the underlying key pair is not destroyed by this function. Only the handle is destroyed.

See Also

CPDeriveKey, CPGenKey, CPGetUserKey, CryptDestroyKey