Skip to content

Instantly share code, notes, and snippets.

@anmolsukki
Created February 14, 2021 06:43
Show Gist options
  • Save anmolsukki/5035fe8869b5bd2c4288be59950b6b4a to your computer and use it in GitHub Desktop.
Save anmolsukki/5035fe8869b5bd2c4288be59950b6b4a to your computer and use it in GitHub Desktop.

Encrypt To Decrypt

var CryptoJS = require("crypto-js");
function encryptData(data, key) {
let ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), key);
return ciphertext.toString()
}
function deEncryptData(data, key) {
let bytes = CryptoJS.AES.decrypt(data.toString(), key);
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8))
}
const encryptResult = encryptData("anmol123", "gyftr@123")
const deEncrypResult = deEncryptData(encryptResult, "gyftr@123")
console.log("====encrypt====>>", encryptResult)
console.log("====dencrypt====>>", deEncrypResult)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment