Sample code for 30+ languages & platforms
Node.js

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var cert = new chilkat.Cert();

    success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem");
    if (success == false) {
        console.log(cert.LastErrorText);
        return;
    }

    var pubKey = new chilkat.PublicKey();
    cert.GetPublicKey(pubKey);

    var rsa = new chilkat.Rsa();
    rsa.UsePublicKey(pubKey);

    rsa.EncodingMode = "base64";
    var encryptedStr = rsa.EncryptStringENC("hello",false);
    console.log("encrypted string = " + encryptedStr);

}

chilkatExample();