This module provides functions to encrypt and decrypt text using AES-256-CBC in Node.js.
Ensure you have Node.js installed on your system. You can install the module by cloning the repository and installing the dependencies:
npm i aes-256-cbc-encryption
The encrypt
function encrypts a given text using a 32-byte key and a 16-byte initialization vector (IV).
text
(string): The text to be encrypted.key
(string): A key with a length of 32 bytes (256 bits).initVector
(string): A 16-byte initialization vector (IV).
string
: The encrypted text in base64 format.
The decrypt
function decrypts a given encrypted text using a 32-byte key and a 16-byte initialization vector (IV).
text
(string): The encrypted text in base64 format.key
(string): A key with a length of 32 bytes (256 bits).initVector
(string): A 16-byte initialization vector (IV).
string
: The decrypted text.
Here's an example of how to use the module:
Set environment variables, for example
# .env
AES_KEY=bf3c199c2470cb477d907b1e0917c17b
AES_IV=5183666c72eec9e4
// index.js
const aes = require("aes-256-cbc-encryption"); // Replace with actual path to your module
const text = "Hello, World!";
// Encrypt the text
const encryptedText = aes.encrypt(text);
console.log(`Encrypted: ${encryptedText}`);
// Decrypt the text
const decryptedText = aes.decrypt(encryptedText);
console.log(`Decrypted: ${decryptedText}`);
OR you can passing parameter directly
// index.js
const aes = require("aes-256-cbc-encryption"); // Replace with actual path to your module
const text = "Hello, World!";
const key = "your-32-byte-long-key-goes-here-123456789012"; // Example key
const initVector = "your-16-byte-iv123"; // Example IV
// Encrypt the text
const encryptedText = aes.encrypt(text, key, initVector);
console.log(`Encrypted: ${encryptedText}`);
// Decrypt the text
const decryptedText = aes.decrypt(encryptedText, key, initVector);
console.log(`Decrypted: ${decryptedText}`);
Nauval S
MIT License