Sample code for 30+ languages & platforms
JavaScript

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.
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 cert = new CkCert();
success = cert.LoadFromFile("C:/certs_and_keys/Certificate.cer");
if (success == false) {
    console.log(cert.LastErrorText);
    return;
}

var sbPem = new CkStringBuilder();
success = sbPem.LoadFile("C:/certs_and_keys/PrivateKey.pem","utf-8");
if (success == false) {
    console.log("Failed to load private key PEM");
    return;
}

success = cert.SetPrivateKeyPem(sbPem.GetAsString());
if (success == false) {
    console.log(cert.LastErrorText);
    return;
}

console.log("The certificate and associated private key are now loaded and ready for signing.");