BCryptDuplicateKey function

The BCryptDuplicateKey function creates a duplicate of a symmetric key.


NTSTATUS BCryptDuplicateKey(
  PUCHAR            pbKeyObject,
  ULONG             cbKeyObject,
  ULONG             dwFlags



The handle of the key to duplicate. This must be a handle to a symmetric key.


A pointer to a BCRYPT_KEY_HANDLE variable that receives the handle of the duplicate key. This handle is used in subsequent functions that require a key, such as BCryptEncrypt. This handle must be released when it is no longer needed by passing it to the BCryptDestroyKey function.


A pointer to a buffer that receives the duplicate key object. The cbKeyObject parameter contains the size of this buffer. The required size of this buffer can be obtained by calling the BCryptGetProperty function to get the BCRYPT_OBJECT_LENGTH property. This will provide the size of the key object for the specified algorithm.

This memory can only be freed after the phNewKey key handle is destroyed.


The size, in bytes, of the pbKeyObject buffer.


A set of flags that modify the behavior of this function. No flags are currently defined, so this parameter should be zero.

Return Value

Returns a status code that indicates the success or failure of the function.

Possible return codes include, but are not limited to, the following.

Return code Description
The function was successful.
The size of the key object specified by the cbKeyObject parameter is not large enough to hold the key object.
The key handle in the hKey parameter is not valid. This value is also returned if the key to duplicate is not a symmetric key.
One or more parameters are not valid.


Depending on what processor modes a provider supports, BCryptDuplicateKey can be called either from user mode or kernel mode. Kernel mode callers can execute either at PASSIVE_LEVEL IRQL or DISPATCH_LEVEL IRQL. If the current IRQL level is DISPATCH_LEVEL, the handle provided in the hKey parameter must be derived from an algorithm handle returned by a provider that was opened with the BCRYPT_PROV_DISPATCH flag, and any pointers passed to the BCryptDuplicateKey function must refer to nonpaged (or locked) memory.

To call this function in kernel mode, use Cng.lib, which is part of the Driver Development Kit (DDK). Windows Server 2008 and Windows Vista:  To call this function in kernel mode, use Ksecdd.lib.


Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header bcrypt.h
Library Bcrypt.lib
DLL Bcrypt.dll