PFXExportCertStore function (wincrypt.h)

The PFXExportCertStore function exports the certificates and, if available, the associated private keys from the referenced certificate store. This is an old function kept for compatibility with Internet Explorer 4.0 clients. New applications should use the PfxExportCertStoreEx function that provides enhanced private key security.

Syntax

BOOL PFXExportCertStore(
  [in]      HCERTSTORE      hStore,
  [in, out] CRYPT_DATA_BLOB *pPFX,
  [in]      LPCWSTR         szPassword,
  [in]      DWORD           dwFlags
);

Parameters

[in] hStore

Handle of the certificate store containing the certificates to be exported.

[in, out] pPFX

A pointer to a CRYPT_DATA_BLOB structure to contain the PFX packet with the exported certificates and keys. If pPFX->pbData is NULL, the function calculates the number of bytes needed for the encoded BLOB and returns this in pPFX->cbData. When the function is called with pPFX->pbData pointing to an allocated buffer of the needed size, the function copies the encoded bytes into the buffer and updates pPFX->cbData with the encode byte length.

[in] szPassword

String password used to encrypt and verify the PFX packet. When you have finished using the password, clear the password from memory by calling the SecureZeroMemory function. For more information about protecting passwords, see Handling Passwords.

[in] dwFlags

Flag values can be set to any combination of the following.

Value Meaning
EXPORT_PRIVATE_KEYS
Private keys are exported as well as the certificates.
REPORT_NO_PRIVATE_KEY
If a certificate is encountered that has no associated private key, the function returns FALSE with the last error set to either CRYPT_E_NOT_FOUND or NTE_NO_KEY.
REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
If a certificate is encountered that has a non-exportable private key, the function returns FALSE and the last error set to NTE_BAD_KEY, NTE_BAD_KEY_STATE, or NTE_PERM.

Return value

Returns TRUE (nonzero) if the function succeeds, and FALSE (zero) if the function fails. For extended error information, call GetLastError.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps | UWP apps]
Minimum supported server Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header wincrypt.h
Library Crypt32.lib
DLL Crypt32.dll

See also

PFXExportCertStoreEx

PFXImportCertStore