PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC callback function (wincrypt.h)

[The PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC function is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.]

The PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC function encrypts the private key and returns the encrypted contents in the pbEncryptedKey parameter. It is a callback function identified in a CRYPT_PKCS8_EXPORT_PARAMS structure that creates a PKCS #8 CRYPT_ENCRYPTED_PRIVATE_KEY_INFO structure. The function must be implemented by the developer to suit each application.

Syntax

PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC PcryptEncryptPrivateKeyFunc;

BOOL PcryptEncryptPrivateKeyFunc(
  [out]     CRYPT_ALGORITHM_IDENTIFIER *pAlgorithm,
  [in]      CRYPT_DATA_BLOB *pClearTextPrivateKey,
  [out]     BYTE *pbEncryptedKey,
  [in, out] DWORD *pcbEncryptedKey,
  [in]      LPVOID pVoidEncryptFunc
)
{...}

Parameters

[out] pAlgorithm

A pointer to a CRYPT_ALGORITHM_IDENTIFIER structure to receive the algorithm used to encrypt the PrivateKeyInfo ASN.1 type found in the PKCS #8 standard.

[in] pClearTextPrivateKey

A pointer to a CRYPT_DATA_BLOB structure that contains the plaintext private key to be encrypted.

[out] pbEncryptedKey

A pointer to a BYTE buffer to receive the encrypted private key BLOB. If this parameter is NULL, pcbEncryptedKey will return the size, in bytes, of memory needed to contain the encrypted key on a subsequent call to this function.

[in, out] pcbEncryptedKey

A pointer to a DWORD variable that contains the size, in bytes, of the pbEncryptedKey buffer. If pbEncryptedKey is NULL, then pcbEncryptedKey is set to the size, in bytes, required to encrypt the key. For more information, see Retrieving Data of Unknown Length.

[in] pVoidEncryptFunc

An LPVOID variable that contains data used for encryption, such as key, initialization vector, and password.

Return value

If the function succeeds, the function returns nonzero (TRUE).

If the function fails, it returns zero (FALSE).

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header wincrypt.h

See also

CRYPT_PKCS8_EXPORT_PARAMS

PCRYPT_DECRYPT_PRIVATE_KEY_FUNC