CryptExportPublicKeyInfoEx function (wincrypt.h)
The CryptExportPublicKeyInfoEx function exports the public key information associated with the provider's corresponding private key. This function allows the application to specify the public key algorithm, overriding the default provided by the cryptographic service provider (CSP).
Syntax
BOOL CryptExportPublicKeyInfoEx(
[in] HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProvOrNCryptKey,
[in] DWORD dwKeySpec,
[in] DWORD dwCertEncodingType,
[in] LPSTR pszPublicKeyObjId,
[in] DWORD dwFlags,
[in] void *pvAuxInfo,
[out] PCERT_PUBLIC_KEY_INFO pInfo,
[in, out] DWORD *pcbInfo
);
Parameters
[in] hCryptProvOrNCryptKey
A handle of the CSP to use when exporting the public key information. This handle must be an HCRYPTPROV handle that has been created by using the CryptAcquireContext function or an NCRYPT_KEY_HANDLE handle that has been created by using the NCryptOpenKey function. New applications should always pass in the NCRYPT_KEY_HANDLE handle of a CNG CSP.
[in] dwKeySpec
Identifies the private key to use from the provider's container. It can be AT_KEYEXCHANGE or AT_SIGNATURE. This parameter is ignored if an NCRYPT_KEY_HANDLE is used in the hCryptProvOrNCryptKey parameter.
[in] dwCertEncodingType
Specifies the encoding type used. It is always acceptable to specify both the certificate and message encoding types by combining them with a bitwise-OR operation as shown in the following example:
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
Currently defined encoding types are:
- X509_ASN_ENCODING
- PKCS_7_ASN_ENCODING
[in] pszPublicKeyObjId
Specifies the public key algorithm.
[in] dwFlags
A DWORD flag value that indicates how the public key information is exported. The flag value is passed directly to the CryptFindOIDInfo function when mapping the public key object identifier to the corresponding CNG public key algorithm Unicode string. The following flag values can be set.
Value | Meaning |
---|---|
|
Skips public keys in the CRYPT_PUBKEY_ALG_OID_GROUP_ID group explicitly flagged with the CRYPT_OID_PUBKEY_ENCRYPT_ONLY_FLAG flag. |
|
Skips public keys in the CRYPT_PUBKEY_ALG_OID_GROUP_ID group explicitly flagged with the CRYPT_OID_PUBKEY_SIGN_ONLY_FLAG flag. |
[in] pvAuxInfo
This parameter is reserved for future use and must be set to NULL.
[out] 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
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.
Return code | Description |
---|---|
|
An export function that can be installed or registered could not be found for the specified dwCertEncodingType and pszPublicKeyObjId parameters. |
|
If the buffer specified by the pInfo parameter is not large enough to hold the returned data, the function sets the ERROR_MORE_DATA code and stores the required buffer size, in bytes, in the variable pointed to by the pcbInfo parameter. |
If the function fails, GetLastError may return an Abstract Syntax Notation One (ASN.1) encoding/decoding error. For information about these errors, see ASN.1 Encoding/Decoding Return Values.
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 |
Library | Crypt32.lib |
DLL | Crypt32.dll |