CryptExportPublicKeyInfoFromBCryptKeyHandle function (wincrypt.h)

The CryptExportPublicKeyInfoFromBCryptKeyHandle function exports the public key information associated with a provider's corresponding private key.


BOOL CryptExportPublicKeyInfoFromBCryptKeyHandle(
  [in]            BCRYPT_KEY_HANDLE     hBCryptKey,
  [in]            DWORD                 dwCertEncodingType,
  [in, optional]  LPSTR                 pszPublicKeyObjId,
  [in]            DWORD                 dwFlags,
  [in, optional]  void                  *pvAuxInfo,
  [out, optional] PCERT_PUBLIC_KEY_INFO pInfo,
  [in, out]       DWORD                 *pcbInfo


[in] hBCryptKey

The handle of the key from which to export the public key information.

[in] dwCertEncodingType

Specifies the encoding type to be matched.

This value can be a bitwise combination of the currently defined encoding types:


[in, optional] pszPublicKeyObjId

A pointer to the object identifier (OID) that identifies the installable function to use to export the key. If the high-order word of the OID is nonzero, pszPublicKeyObjId is a pointer to either an OID string such as "" or an ASCII string such as "file." If the high-order word of the OID is zero, the low-order word specifies the integer identifier to be used as the object identifier.

[in] dwFlags

A DWORD value that indicates how the public key information is exported.

Value Meaning
Skips public keys in the CRYPT_PUBKEY_ALG_OID_GROUP_ID group that are explicitly flagged with the CRYPT_OID_PUBKEY_ENCRYPT_ONLY_FLAG flag.
Skips public keys in the CRYPT_PUBKEY_ALG_OID_GROUP_ID group that are explicitly flagged with the CRYPT_OID_PUBKEY_SIGN_ONLY_FLAG flag.

[in, optional] pvAuxInfo

This parameter is reserved for future use and must be set to NULL.

[out, optional] pInfo

A pointer to a CERT_PUBLIC_KEY_INFO structure to receive the public key information to be exported.

This parameter can be NULL to set the size of this information for memory allocation purposes. For more information, see Retrieving Data of Unknown Length.

[in, out] pcbInfo

A pointer to a DWORD that contains the size, in bytes, of the buffer pointed to by the pInfo parameter. When the function returns, the DWORD contains the number of bytes stored in the buffer.

Return value

The function returns TRUE if it succeeds; otherwise, it returns FALSE.


If the CryptExportPublicKeyInfoFromBCryptKeyHandle function is unable to find an installable OID function for the OID specified by the pszPublicKeyObjId parameter, it attempts to export the key as a RSA Public Key (szOID_RSA_RSA). If the key is exported as a RSA Public Key, the values of the dwFlags and pvAuxInfo parameters are not used.


Requirement Value
Minimum supported client Windows 7 [desktop apps only]
Minimum supported server Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header wincrypt.h
Library Crypt32.lib
DLL Crypt32.dll