RPeraltaJr
3/29/2018 - 6:59 PM

Encrypt and Decrypt

var CryptoJS = require("crypto-js");

var data = "hello world";
// var data = [{id: 1}, {id: 2}]

// Encrypt
var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123');
console.log(ciphertext);

// Decrypt
var bytes  = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123');
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));

console.log(decryptedData);

Install package

npm install crypto-js