Sample code for 30+ languages & platforms
Node.js

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.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var cert = new chilkat.Cert();
    success = cert.LoadFromFile("C:/certs_and_keys/Certificate.cer");
    if (success == false) {
        console.log(cert.LastErrorText);
        return;
    }

    var sbPem = new chilkat.StringBuilder();
    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.");

}

chilkatExample();