Node.js
Node.js
Use Base64 RSA Key to Encrypt
See more RSA Examples
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var pubkey = new chilkat.PublicKey();
success = pubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==");
if (success == false) {
console.log(pubkey.LastErrorText);
return;
}
var rsa = new chilkat.Rsa();
success = rsa.UsePublicKey(pubkey);
if (success == false) {
console.log(rsa.LastErrorText);
return;
}
rsa.EncodingMode = "base64";
var encryptedStr = rsa.EncryptStringENC("12345678",false);
console.log(encryptedStr);
}
chilkatExample();