1 out of 2 rated this helpful - Rate this topic

CryptExportPKCS8Ex function

[The CryptExportPKCS8Ex function is no longer available for use as of Windows Server 2008 and Windows Vista. Instead, use the PFXExportCertStoreEx function.]

Applies to: desktop apps only

The CryptExportPKCS8Ex function exports the private key in PKCS #8 format. This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Crypt32.dll.

Syntax

BOOL WINAPI CryptExportPKCS8Ex(
  __in       CRYPT_PKCS8_EXPORT_PARAMS *psExportParams,
  __in       DWORD dwFlags,
  __in_opt   void *pvAuxInfo,
  __out_opt  BYTE *pbPrivateKeyBlob,
  __inout    DWORD *pcbPrivateKeyBlob
);

Parameters

psExportParams [in]

A pointer to a CRYPT_PKCS8_EXPORT_PARAMS structure that contains information about the key to export.

dwFlags [in]

This parameter should be zero if pbPrivateKeyBlob is NULL and 0x8000 otherwise.

pvAuxInfo [in, optional]

This parameter must be NULL.

pbPrivateKeyBlob [out, optional]

A pointer to an array of BYTE structures to receive the private key to be exported. The private key will contain the information in a PKCS #8 PrivateKeyInfo Abstract Syntax Notation One (ASN.1) type found in the PKCS #8 standard.

For memory allocation purposes, you can get the size of the private key to be exported by setting this parameter to NULL. For more information, see Retrieving Data of Unknown Length.

pcbPrivateKeyBlob [in, out]

A pointer to a DWORD that may contain, on input, the size, in bytes, of the memory allocation needed to contain the pbPrivateKeyBlob. If pbPrivateKeyBlob is NULL, this parameter will return the size of the memory allocation needed for a second call to the function. For more information, see Retrieving Data of Unknown Length.

Return value

If the function succeeds, the function returns nonzero (TRUE).

If the function fails, it returns zero (FALSE). For extended error information, call GetLastError.

The following error codes are specific to this function.

Return codeDescription
ERROR_UNSUPPORTED_TYPE

An export function that can be installed or registered could not be found.

ERROR_MORE_DATA

If the buffer specified by the pbPrivateKeyBlob 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 pcbPrivateKeyBlob parameter.

 

If the function fails, GetLastError returns an ASN.1 encoding/decoding error. For information about these errors, see ASN.1 Encoding/Decoding Return Values.

Remarks

This function is only supported for asymmetric keys.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

End of client support

Windows XP

End of server support

Windows Server 2003

Header

Wincrypt.h

DLL

Crypt32.dll

See also

CryptAcquireContext
CryptExportPKCS8
CryptImportPKCS8
CRYPT_PKCS8_EXPORT_PARAMS

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ