• Using the RSA Private Key for Decryption

    Parameters

    • privateKey: Buffer

      Private key. Note: Do not enter sensitive information in plaintext in the code.

    • cipherText: Buffer

      Ciphertext

    • Optional padding: RSAPadding

      Filling mode. The default value is PKCS1.

    Returns Buffer

    Example


    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");