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.



BOOL PfnCmsgExportKeyTrans(
  [in]      PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  [in, out] PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  [in]      DWORD dwFlags,
            void *pvReserved


[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.


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.


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


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