PFN_CMSG_EXPORT_KEY_TRANS callback function (wincrypt.h)

The PFN_CMSG_EXPORT_KEY_TRANS callback function encrypts and exports the content encryption key for a key transport recipient of an enveloped message. PFN_CMSG_EXPORT_KEY_TRANS can be installed by using a CryptoAPI object identifier (OID). This function is called by the CryptMsgOpenToEncode function when its dwMsgType parameter is set to CMSG_ENVELOPED.

Syntax

PFN_CMSG_EXPORT_KEY_TRANS PfnCmsgExportKeyTrans;

BOOL PfnCmsgExportKeyTrans(
  [in]      PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  [in]      PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
  [in, out] PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  [in]      DWORD dwFlags,
            void *pvReserved
)
{...}

Parameters

[in] pContentEncryptInfo

A pointer to a CMSG_CONTENT_ENCRYPT_INFO structure that contains the content encryption key.

[in] pKeyTransEncodeInfo

A pointer to a CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO structure that specifies the recipient public key used to encrypt the content encryption key.

[in, out] pKeyTransEncryptInfo

A pointer to a CMSG_KEY_TRANS_ENCRYPT_INFO structure that contains the encrypted content encryption key.

[in] dwFlags

This value is not used. Set it to zero.

pvReserved

This value is reserved. Set it to NULL.

Return value

If the function succeeds, the return value is nonzero (TRUE).

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

Remarks

The PFN_CMSG_EXPORT_KEY_TRANS function must update the EncryptedKey member of the CMSG_KEY_TRANS_ENCRYPT_INFO structure pointed to by the pKeyTransEncryptInfo parameter. This function must use the pfnAlloc and pfnFree members of the CMSG_CONTENT_ENCRYPT_INFO structure pointed to by the pContentEncryptInfo parameter to manage memory allocation for the encrypted key.

You can use OID Support Functions to deploy this callback function. Wincrypt.h defines the following constants for this purpose.

You must define different callback functions for CAPI1 keys and Cryptography API: Next Generation (CNG) keys. Both functions have the same signature but use different OIDs. Which function is called depends on the value of the fCNG member of the CMSG_CONTENT_ENCRYPT_INFO structure pointed to by the pContentEncryptInfo parameter. The following table shows the relationship between the callback function and the value of the fCNG member.

fCNG value Constant Definition
FALSE CMSG_OID_EXPORT_KEY_TRANS_FUNC or CMSG_OID_CAPI1_EXPORT_KEY_TRANS_FUNC "CryptMsgDllExportKeyTrans"
TRUE CMSG_OID_CNG_EXPORT_KEY_TRANS_FUNC "CryptMsgDllCNGExportKeyTrans"

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