Platform SDK: Cryptography

CPDestroyKey

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

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

Parameters

hProv
Handle to a particular key container within the CSP. This handle is obtained by a call to CPAcquireContext.
hKey
Handle to the key to be destroyed.

Return Values

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE, and the appropriate error code from the following table must be set using 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 imported into the CSP with CryptImportKey, this function destroys the key and frees the memory that the key occupied. A CSP typically scrubs 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.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 OSR2 or later (or Windows 95 with Internet Explorer 3.02 or later).
  Header: Declared in Wincrypt.h.

See Also

CPDeriveKey, CPGenKey, CPGetUserKey, CryptDestroyKey