BCryptImportKeyPair

The BCryptImportKeyPair function imports a public/private key pair from a key BLOB. The BCryptImportKey function is used to import a symmetric key pair.

Syntax

NTSTATUS BCryptImportKeyPair(
         BCRYPT_ALG_HANDLE hAlgorithm,
         BCRYPT_KEY_HANDLE hImportKey,
         LPCWSTR pszBlobType,
         BCRYPT_KEY_HANDLE *phKey,
         PUCHAR pbInput,
         ULONG cbInput,
         ULONG dwFlags
)  

Parameters

hAlgorithm
Type: BCRYPT_ALG_HANDLE 

[in] The handle of the algorithm provider to import the key. This handle is obtained by calling the BCryptOpenAlgorithmProvider function.

hImportKey
Type: BCRYPT_KEY_HANDLE 

[in, optional] This parameter is not currently used and should be NULL.

pszBlobType
Type: LPCWSTR 

[in] A null-terminated Unicode string that contains an identifier that specifies the type of BLOB that is contained in the pbInput buffer. This can be one of the following values.

phKey
Type: BCRYPT_KEY_HANDLE *

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

pbInput
Type: PUCHAR 

[in] The address of a buffer that contains the key BLOB to import. The cbInput parameter contains the size of this buffer. The pszBlobType parameter specifies the type of key BLOB this buffer contains.

cbInput
Type: ULONG 

[in] The size, in bytes, of the pbInput buffer.

dwFlags
Type: ULONG 

[in] A set of flags that modify the behavior of this function. This can be zero or the following value.

Return value

Type: NTSTATUS 

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

Return codes

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

Return code Description
STATUS_SUCCESS The function was successful.
STATUS_INVALID_HANDLE The algorithm handle in the hAlgorithm parameter is not valid.
STATUS_INVALID_PARAMETER One or more parameters are not valid.
STATUS_NOT_SUPPORTED The algorithm provider specified by the hAlgorithm parameter does not support the BLOB type specified by the pszBlobType parameter.

Remarks

Depending on what processor modes a provider supports, BCryptImportKeyPair can be called either from user mode or kernel mode. Kernel mode callers can execute either at PASSIVE_LEVELIRQL or DISPATCH_LEVEL IRQL. If the current IRQL level is DISPATCH_LEVEL, the handle provided in the hAlgorithm parameter must have been opened by using the BCRYPT_PROV_DISPATCH flag, and any pointers passed to the BCryptImportKeyPair function must refer to nonpaged (or locked) memory.

Requirements

Header: Declared in bcrypt.h.

Library: Use bcrypt.lib.