Partager via


CryptExportPublicKeyInfo (Compact 2013)

3/28/2014

This function exports the public key information associated with the provider's corresponding private key.

Syntax

BOOL WINAPI CryptExportPublicKeyInfo(
    __in HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProvOrNCryptKey,
    __in DWORD dwKeySpec,
    __in DWORD dwCertEncodingType,
    __out PCERT_PUBLIC_KEY_INFO pInfo,
    __inout DWORD *pcbInfo
);

Parameters

  • hCryptProvOrNCryptKey
    [in] Handle of the cryptographic service provider (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 cryptography next generation (CNG) CSP.
  • dwKeySpec
    [in] Identifies the private key to use from the container of the provider. This parameter can be AT_KEYEXCHANGE or AT_SIGNATURE. This parameter is ignored if an NCRYPT_KEY_HANDLE is used in the hCryptProvOrNCryptKey parameter.
  • dwCertEncodingType
    [in] Specifies the encoding type used. You can specify both the certificate and the 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

  • pInfo
    [out] Pointer to a CERT_PUBLIC_KEY_INFO structure to receive the public key information to be exported.

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

  • pcbInfo
    [in, out] 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 needed for the return buffer.

    Note

    When processing the data returned in the buffer, applications need to use the actual size of the data returned. The actual size can be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to ensure that the largest possible output data will fit in the buffer.) On output, the variable pointed to by this parameter is updated to reflect the actual size of the data copied to the buffer.

Return Value

If the function succeeds, the function returns nonzero (TRUE); otherwise, it is zero (FALSE).

For extended error information, call GetLastError.

Note

Errors from the called functions CryptGetUserKey and CryptExportKey might be propagated to this function.

The following table shows the error codes for the GetLastError function.

Error code

Description

ERROR_MORE_DATA

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, into the variable pointed to by pcbInfo.

ERROR_FILE_NOT_FOUND

Invalid certificate encoding type. Currently only X509_ASN_ENCODING is supported.

If the function was not successful, 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

Header

wincrypt.h

Library

crypt32.lib

See Also

Reference

Certificates Functions