Sample code for 30+ languages & platforms
JavaScript

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var certStore = new CkCertStore();

var pfxPath = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
var pfxPassword = "test";
success = certStore.LoadPfxFile(pfxPath,pfxPassword);
if (success !== true) {
    console.log(certStore.LastErrorText);
    return;
}

var numCerts = certStore.NumCertificates;

console.log("PFX contains " + numCerts + " certificates");

var cert = new CkCert();
var i = 0;
while (i < numCerts) {
    certStore.GetCert(i,cert);

    console.log(i + ": (Common Name) " + cert.SubjectCN);
    console.log(i + ": (Serial Number) " + cert.SerialNumber);
    console.log(i + ": (Distinguished Name) " + cert.SubjectDN);

    i = i+1;
}