CryptExportPublicKeyInfoFromBCryptKeyHandle function

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

Syntax

BOOL CryptExportPublicKeyInfoFromBCryptKeyHandle(
  BCRYPT_KEY_HANDLE     hBCryptKey,
  DWORD                 dwCertEncodingType,
  LPSTR                 pszPublicKeyObjId,
  DWORD                 dwFlags,
  void                  *pvAuxInfo,
  PCERT_PUBLIC_KEY_INFO pInfo,
  DWORD                 *pcbInfo
);

Parameters

hBCryptKey

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

dwCertEncodingType

Specifies the encoding type to be matched.

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

  • X509_ASN_ENCODING
  • PKCS_7_ASN_ENCODING

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 "2.5.29.1" 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.

dwFlags

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

Value Meaning
CRYPT_OID_INFO_PUBKEY_SIGN_KEY_FLAG
0x80000000
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.
CRYPT_OID_INFO_PUBKEY_ENCRYPT_KEY_FLAG
0x40000000
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.

pvAuxInfo

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

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.

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.

Remarks

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.

Requirements

   
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