Sample code for 30+ languages & platforms
JavaScript

Get Public Key from Certificate PEM

See more Certificates Examples

Loads a certificate from a PEM file and gets the cert's public key.
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("qa_data/certs/someCert.pem");
if (success == false) {
    console.log(cert.LastErrorText);
    return;
}

// Get the certificate's public key:
var pubkey = new CkPublicKey();
cert.GetPublicKey(pubkey);

console.log(pubkey.GetPem(false));

// OK.. we have the public key which can be used in other Chilkat classes/methods...