Pfx ActiveX Reference Documentation

Pfx

Provides the ability to manage, parse, and read PFX (PKCS12) files. To create PFX (PKCS12) files, use the certificate object's ExportToPfxFile or ExportToPfxData methods.

Object Creation

(Visual Basic 6.0)
Dim obj As New ChilkatPfx

(ASP)
set obj = Server.CreateObject("Chilkat_9_5_0.Pfx")

(VBScript)
set obj = CreateObject("Chilkat_9_5_0.Pfx")

(Delphi)
obj := TChilkatPfx.Create(Self);

(FoxPro)
loObject = CreateObject('Chilkat_9_5_0.Pfx')

(PowerBuilder)
lole_object = create oleobject
li_rc = lole_object.ConnectToNewObject("Chilkat_9_5_0.Pfx")

(SQL Server)
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Pfx', @obj OUT

(Javascript)
var obj = new ActiveXObject("Chilkat_9_5_0.Pfx");

Properties

DebugLogFilePath As String

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

LastBinaryResult As Variant (read-only)

Introduced in version 9.5.0.52

The binary data returned by the last (binary data returning) method called. Only available if Chilkat.Global.KeepBinaryResult is set to 1. This provides a means for obtaining large varbinary results in the SQL Server environment (where limitations exist in getting large amounts of data returned by method calls, but where temp tables can be used for binary properties).

LastErrorHtml As String (read-only)

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastErrorText As String (read-only)

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

Concept of LastErrorText

LastErrorText Standard Information

LastErrorXml As String (read-only)

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastMethodSuccess As Long

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of 1 indicates success, a value of 0 indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = 1 and failure = 0.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to 1. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

LastStringResult As String (read-only)

Introduced in version 9.5.0.52

The string return value of the last (string returning) method called. Only available if Chilkat.Global.KeepStringResult is set to 1. This provides a means for obtaining large string results in the SQL Server environment (where limitations exist in getting long strings returned by method calls, but where temp tables can be used for string properties).

Long Strings Returned by ActiveX Methods in SQL Server

LastStringResultLen As Long (read-only)

Introduced in version 9.5.0.53

The length, in characters, of the string contained in the LastStringResult property.

NumCerts As Long (read-only)

Introduced in version 9.5.0.40

The number of certificates contained in the PFX.

NumPrivateKeys As Long (read-only)

Introduced in version 9.5.0.40

The number of private keys contained in the PFX.

VerboseLogging As Long

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

Version As String (read-only)

Version of the component/library, such as "9.5.0.63"

Methods

AddCert(cert As ChilkatCert, ByVal includeChain As Long) As Long

Introduced in version 9.5.0.44

Adds a certificate, its private key (if it exists), and potentially its certificate chain to the PFX. If includeChain is 1, then the certificate must have a private key. The certificate's private key is automatically obtained (internally) via the cert's ExportPrivateKey method. If the certificate's chain of authentication is to be added, it is automatically constructed and added using whatever resources are at hand (such as certs provided via the UseCertVault method, the trusted roots from Chilkat's TrustedRoots class, etc. If a certificate chain is to be added, which is the typical case, then the chain must be completed to the root to succeed.

Returns 1 for success, 0 for failure.

AddPrivateKey(privKey As PrivateKey, certChain As ChilkatCertChain) As Long

Introduced in version 9.5.0.44

Adds a private key and certificate chain to the PFX. The private key should be such that it is associated with the 1st certificate in the chain. In other words, the 1st certificate in the chain has a public key (embedded within the X.509 structure of the cert itself) that is the counterpart to the private key.

Returns 1 for success, 0 for failure.

(Classic ASP) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

(Visual FoxPro) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

(PowerBuilder) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

(SQL Server) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

(Visual Basic 6.0) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

(VBScript) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

GetCert(ByVal index As Long) As ChilkatCert

Introduced in version 9.5.0.40

Returns the Nth certificate in the PFX. (The 1st certificate is at index 0.)

Returns Nothing on failure

GetPrivateKey(ByVal index As Long) As PrivateKey

Introduced in version 9.5.0.40

Returns the Nth private key in the PFX. (The 1st private key is at index 0.)

Returns Nothing on failure

(Classic ASP) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(Visual FoxPro) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(PowerBuilder) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(SQL Server) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(Visual Basic 6.0) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(VBScript) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

LoadPem(pemStr As String, password As String) As Long

Introduced in version 9.5.0.47

Loads a PFX from a PEM formatted string. The PEM can contain the private key, the certificate, and certificates in the chain of authentication up to the CA root. For example:

 -----BEGIN RSA PRIVATE KEY-----
...
... the private key associated with the main certificate.
...
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
...
... the main certificate
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
...
... an intermediate CA certificate (if present)
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
...
... the root CA certificate
...
-----END CERTIFICATE----- 

Returns 1 for success, 0 for failure.

LoadPfxBytes(pfxData As Variant, password As String) As Long

Introduced in version 9.5.0.40

Loads a PFX from in-memory bytes.

Returns 1 for success, 0 for failure.

LoadPfxEncoded(encodedData As String, encoding As String, password As String) As Long

Introduced in version 9.5.0.40

Loads a PFX from encoded byte data. The encoding can by any encoding, such as "Base64", "modBase64", "Base32", "UU", "QP" (for quoted-printable), "URL" (for url-encoding), "Hex", "Q", "B", "url_oath", "url_rfc1738", "url_rfc2396", and "url_rfc3986".

Returns 1 for success, 0 for failure.

List of Supported Encodings (Base64, Hex, etc.)

LoadPfxFile(path As String, password As String) As Long

Introduced in version 9.5.0.40

Loads a PFX from a file.

Returns 1 for success, 0 for failure.

(Classic ASP) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(Visual FoxPro) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(PowerBuilder) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(SQL Server) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(Visual Basic 6.0) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

(VBScript) RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature

ToBinary(password As String) As Variant

Introduced in version 9.5.0.44

Write the PFX to in-memory bytes.

Returns a zero-length byte array (as a Variant) on failure.
An empty array will have a UBound of -1 meaning 0 elements.

ToEncodedString(password As String, encoding As String) As String

Introduced in version 9.5.0.44

Write the PFX to an encoded string. The encoding can be any encoding such as "base64" or "hex".

Returns Nothing on failure

List of Supported Encodings (Base64, Hex, etc.)

ToFile(password As String, path As String) As Long

Introduced in version 9.5.0.44

Write the PFX to a file. PFX and PKCS12 are essentially the same. Standard filename extensions are ".pfx" or ".p12".

Returns 1 for success, 0 for failure.

(Classic ASP) Create .pfx/.p12 from Certificate and Private Key PEM Files

(Visual FoxPro) Create .pfx/.p12 from Certificate and Private Key PEM Files

(PowerBuilder) Create .pfx/.p12 from Certificate and Private Key PEM Files

(SQL Server) Create .pfx/.p12 from Certificate and Private Key PEM Files

(Visual Basic 6.0) Create .pfx/.p12 from Certificate and Private Key PEM Files

(VBScript) Create .pfx/.p12 from Certificate and Private Key PEM Files

ToJavaKeyStore(alias As String, password As String) As ChilkatJavaKeyStore

Introduced in version 9.5.0.44

Converts the PFX (PKCS12) to a JavaKeyStore object. One JKS entry per private key found in the PKCS12 is added. The certs found within the PCKS12 are used to build the certificate chains for each private key. (A typical PFX file contains a single private key along with its associated certificate, and the certificates in the chain of authentication to the root CA cert.)

The specified alias is applied to the 1st private key found. If the alias is empty, then the alias is obtained from the cert/PFX in the following order of preference:

  1. Certificate's subject common name
  2. Certificate's subject email address
  3. Certificate's friendly name found in the PKCS9 attributes of the PKCS12
  4. Certificate's serial number

If multiple private keys are found in the PKCS12, then all but the first will automaticallly be assigned aliases using the preference just described.

Returns Nothing on failure

(Classic ASP) Convert PFX to JWK Set

(Visual FoxPro) Convert PFX to JWK Set

(PowerBuilder) Convert PFX to JWK Set

(SQL Server) Convert PFX to JWK Set

(Visual Basic 6.0) Convert PFX to JWK Set

(VBScript) Convert PFX to JWK Set

(Classic ASP) Convert PKCS12 / PFX to Java Keystore (JKS)

(Visual FoxPro) Convert PKCS12 / PFX to Java Keystore (JKS)

(PowerBuilder) Convert PKCS12 / PFX to Java Keystore (JKS)

(SQL Server) Convert PKCS12 / PFX to Java Keystore (JKS)

(Visual Basic 6.0) Convert PKCS12 / PFX to Java Keystore (JKS)

(VBScript) Convert PKCS12 / PFX to Java Keystore (JKS)

ToPem() As String

Introduced in version 9.5.0.47

Write the PFX to a PEM formatted string. The resultant PEM will contain the private key, as well as the certs in the chain of authentication (or whatever certs are available in the PFX). For example:

 -----BEGIN RSA PRIVATE KEY-----
...
... the private key associated with the main certificate.
...
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
...
... the main certificate
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
...
... an intermediate CA certificate (if present)
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
...
... the root CA certificate
...
-----END CERTIFICATE----- 

Returns Nothing on failure

(Classic ASP) Convert PFX to PEM

(Visual FoxPro) Convert PFX to PEM

(PowerBuilder) Convert PFX to PEM

(SQL Server) Convert PFX to PEM

(Visual Basic 6.0) Convert PFX to PEM

(VBScript) Convert PFX to PEM

(Classic ASP) Convert PFX with ECC Private Key and Cert to PEM

(Visual FoxPro) Convert PFX with ECC Private Key and Cert to PEM

(PowerBuilder) Convert PFX with ECC Private Key and Cert to PEM

(SQL Server) Convert PFX with ECC Private Key and Cert to PEM

(Visual Basic 6.0) Convert PFX with ECC Private Key and Cert to PEM

(VBScript) Convert PFX with ECC Private Key and Cert to PEM

ToPemEx(ByVal extendedAttrs As Long, ByVal noKeys As Long, ByVal noCerts As Long, ByVal noCaCerts As Long, encryptAlg As String, password As String) As String

Introduced in version 9.5.0.49

Write the PFX to a PEM formatted string. If extendedAttrs is 1, then extended properties (Bag Attributes and Key Attributes) are output. If noKeys is 1, then no private keys are output. If noCerts is 1, then no certificates are output. If noCaCerts is 1, then no CA certs or intermediate CA certs are output. If encryptAlg is not empty, it indicates the encryption algorithm to be used for encrypting the private keys (otherwise the private keys are output unencrypted). The possible choices for the encryptAlg are "des3", "aes128", "aes192", and "aes256". (All encryption algorithm choices use CBC mode.) If the private keys are to be encrypted, then password is the password to be used. Otherwise, password may be left empty. For example:

Bag Attributes
    Microsoft Local Key set: <No Values>
    localKeyID: 01 00 00 00 
    friendlyName: le-2b09a3d2-9037-4a05-95cc-4d44518e8607
    Microsoft CSP Name: Microsoft RSA SChannel Cryptographic Provider
Key Attributes
    X509v3 Key Usage: 10 
 -----BEGIN RSA PRIVATE KEY-----
...
... the private key associated with the main certificate.
...
-----END RSA PRIVATE KEY-----
Bag Attributes
    localKeyID: 01 00 00 00 
    1.3.6.1.4.1.311.17.3.92: 00 08 00 00 
    1.3.6.1.4.1.311.17.3.20: C2 53 54 F3 ...
    1.3.6.1.4.1.311.17.3.71: 49 00 43 00 ...
    1.3.6.1.4.1.311.17.3.75: 31 00 42 00 ...
subject=/OU=Domain Control Validated/OU=PositiveSSL/CN=something.com
issuer=/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
-----BEGIN CERTIFICATE-----
...
... the main certificate
...
-----END CERTIFICATE-----
...
-----BEGIN CERTIFICATE-----
...
... an intermediate CA certificate (if present)
...
-----END CERTIFICATE-----
...
-----BEGIN CERTIFICATE-----
...
... the root CA certificate
...
-----END CERTIFICATE----- 

Returns Nothing on failure

(Classic ASP) Convert PFX to Encrypted PEM

(Visual FoxPro) Convert PFX to Encrypted PEM

(PowerBuilder) Convert PFX to Encrypted PEM

(SQL Server) Convert PFX to Encrypted PEM

(Visual Basic 6.0) Convert PFX to Encrypted PEM

(VBScript) Convert PFX to Encrypted PEM

(Classic ASP) Convert PFX with ECC Private Key and Cert to Encrypted PEM

(Visual FoxPro) Convert PFX with ECC Private Key and Cert to Encrypted PEM

(PowerBuilder) Convert PFX with ECC Private Key and Cert to Encrypted PEM

(SQL Server) Convert PFX with ECC Private Key and Cert to Encrypted PEM

(Visual Basic 6.0) Convert PFX with ECC Private Key and Cert to Encrypted PEM

(VBScript) Convert PFX with ECC Private Key and Cert to Encrypted PEM

UseCertVault(vault As ChilkatXmlCertVault) As Long

Introduced in version 9.5.0.44

Adds an XML certificate vault to the object's internal list of sources to be searched for certificates for help in building certificate chains to a root certificate.

Returns 1 for success, 0 for failure.