Node Encryption Sample Code

const crypto = require('crypto');


const key = Buffer.from("yourkey", 'hex');
const iv = Buffer.from("yourIV", 'hex');


 Encrypt function 
function encrypt(data) {
   const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
   let encrypted = cipher.update(data, 'utf8', 'hex');
   encrypted += cipher.final('hex');
   return encrypted;
}


 Decrypt function 
function decrypt(encryptedData) {
   const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
   let decrypted = decipher.update(encryptedData, 'hex', 'utf8');
   decrypted += decipher.final('utf8');
   return decrypted;
}


 Example usage 
const plaintext = JSON.stringify({
   p1: "0156543285",
   p2: "ICIC0002122",
   p3: "UB456787654",
   p4: "61a",
   p5: "DEV"
});


const encrypted = encrypt(plaintext);
console.log("Encrypted (Hex):", encrypted);


const decrypted = decrypt(encrypted);
console.log("Decrypted Text:", decrypted);