Private key. Note: Do not enter sensitive information in plaintext in the code.
Ciphertext
Optional
padding: RSAPaddingFilling mode. The default value is PKCS1.
import * as crypto from 'crypto';
import * as buffer from 'buffer';
import * as assert from 'assert';
let rsakey = crypto.generateKey(2048);
let data = buffer.from("something");
let cipherText = crypto.publicEncrypt(rsakey.publicKey, data);
let plainText = crypto.privateDecrypt(rsakey.privateKey, cipherText);
assert.equal(plainText, "something", "not equal");
Using the RSA Private Key for Decryption