Skip to content

Latest commit

 

History

History
168 lines (129 loc) · 4.9 KB

nf-wincrypt-cryptdestroykey.md

File metadata and controls

168 lines (129 loc) · 4.9 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:wincrypt.CryptDestroyKey
CryptDestroyKey function (wincrypt.h)
Releases the handle referenced by the hKey parameter.
CryptDestroyKey
CryptDestroyKey function [Security]
_crypto2_cryptdestroykey
security.cryptdestroykey
wincrypt/CryptDestroyKey
security\cryptdestroykey.htm
security
ed5d8047-c9fd-4765-915f-a6a014004b30
12/05/2018
CryptDestroyKey, CryptDestroyKey function [Security], _crypto2_cryptdestroykey, security.cryptdestroykey, wincrypt/CryptDestroyKey
wincrypt.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
Advapi32.lib
Advapi32.dll
Windows
19H1
CryptDestroyKey
wincrypt/CryptDestroyKey
c++
APIRef
kbSyntax
DllExport
Advapi32.dll
API-MS-Win-Security-cryptoapi-l1-1-0.dll
cryptsp.dll
CryptDestroyKey

CryptDestroyKey function

-description

Important  This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.
 
The CryptDestroyKey function releases the handle referenced by the hKey parameter. After a key handle has been released, it is no longer valid and cannot be used again.

If the handle refers to a session key, or to a public key that has been imported into the cryptographic service provider (CSP) through CryptImportKey, this function destroys the key and frees the memory that the key used. Many CSPs overwrite the memory where the key was held before freeing it. However, the underlying public/private key pair is not destroyed by this function. Only the handle is destroyed.

-parameters

-param hKey [in]

The handle of the key to be destroyed.

-returns

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. For extended error information, call GetLastError.

The error codes prefaced by "NTE" are generated by the particular CSP being used. Some possible error codes are listed in the following table.

Return code Description
ERROR_BUSY
The key object specified by hKey is currently being used and cannot be destroyed.
ERROR_INVALID_HANDLE
The hKey parameter specifies a handle that is not valid.
ERROR_INVALID_PARAMETER
The hKey parameter contains a value that is not valid.
NTE_BAD_KEY
The hKey parameter does not contain a valid handle to a key.
NTE_BAD_UID
The CSP context that was specified when the key was created cannot be found.

-remarks

Keys take up both operating system's memory space and the CSP's memory space. Some CSPs are implemented in hardware with limited memory resources. Applications must destroy all keys with the CryptDestroyKey function when they are finished with them.

All key handles that have been created or imported by using a specific CSP must be destroyed before that CSP handle is released with the CryptReleaseContext function.

Examples

For an example that uses the CryptDestroyKey function, see Example C Program: Creating and Hashing a Session Key.

-see-also

CryptDeriveKey

CryptGenKey

CryptGetUserKey

CryptImportKey

Key Generation and Exchange Functions