Sample code for 30+ languages & platforms
JavaScript

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.
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();

// This only loads the contents of the PFX file into the certStore object.
// It is not importing the PFX into the Windows certificate stores.
var pfxPassword = "badssl.com";
success = certStore.LoadPfxFile("qa_data/pfx/badssl.com-client.p12",pfxPassword);
if (success == false) {
    console.log(certStore.LastErrorText);
    return;
}

// Examine each certificate (loaded from the PFX) in this certStore object
var cert = new CkCert();
var numCerts = certStore.NumCertificates;
var i = 0;
while (i < numCerts) {
    certStore.GetCert(i,cert);
    console.log("hasPrivateKey=" + cert.HasPrivateKey() + ", " + cert.SubjectCN);
    i = i+1;
}