CryptoSys PKI Toolkit Manual

X509_GetCertFromPFX

Extracts an X.509 certificate from a PKCS-12 PFX/.p12 file, saving the output directly as a new file.

VB6/VBA Syntax

Public Declare Function X509_GetCertFromPFX Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPfxFile As String, ByVal strPassword As String, ByVal nOptions As Long) As Long

nRet = X509_GetCertFromPFX(strOutputFile, strPfxFile, strPassword, nOptions) As Long

Parameters

strOutputFile
[in] String specifying the filename of the output file to be created.
strPfxFile
[in] String containing the PFX filename
strPassword
[in] String containing password or "" if certificate is not encrypted [new in v3.8]
nOptions
[in] Long option flags: not used in this release. Specify zero.

C/C++ Syntax

long _stdcall X509_GetCertFromPFX(const char *szOutputFile, const char *szPFXFile, const char *szPassword, long nOptions);

Returns (VB6/C)

Long: If successful, it returns the number of bytes written to the output file; otherwise it returns a negative error code.

.NET Equivalent

X509.GetCertFromPFX Method (String, String)
X509.GetCertFromPFX Method (String, String, String)

Remarks

The first encrypted X.509 certificate or pkcs-12-certBag found in the PFX file containing a x509Certificate will be extracted and saved directly as a DER-encoded X.509 certificate file. Any existing file of the same name will be overwritten without warning.

[New in v3.8:] This will now extract certificates encrypted with the weak 40-bit encryption used by "default" in Microsoft and OpenSSL PKCS-12 files. If no certificate can be found it will now [as of v3.8] return a negative NO_DATA_ERROR error code.

Example

nChars = X509_GetCertFromPFX("mycert.cer", "mypkcs12file.pfx", "password", 0)

will extract the first X.509 certificate, if any, found in the PKCS-12 file mypkcs12file.pfx with password "password", and save it as the new DER-encoded certificate file mycert.cer. The variable nChars will contain the size in bytes of the new file it created.

See Also

X509_GetCertFromP7Chain PFX_MakeFile PFX_VerifySig

[Contents] [Index]

[HOME]   [NEXT: X509_HashIssuerAndSN...]

Copyright © 2004-12 D.I. Management Services Pty Ltd. All rights reserved.