NodeJS Encryption Sample Code
This project demonstrates encryption and decryption using RSA and AES algorithms in Node.js. It includes two main scripts:
generateTestData.js
: Generates RSA key pairs, encrypts data using AES, and encrypts the AES session key using RSA.decrypt.js
: Decrypts the AES session key using RSA and then decrypts the data using the decrypted AES session key.
This script performs the following steps:
- Generates an RSA key pair (public and private keys).
- Saves the private key to a file (
private-key.pem
). - Saves the public key to a file (
public-key.pem
). - Generates a random AES session key.
- Encrypts a sample data string (
encryptme!
) using AES with the generated session key and a random IV (Initialization Vector). - Encrypts the AES session key using the RSA public key.
- Outputs the encrypted session key, encrypted data, and IV in Base64 format.
node generateTestData.js