Created
February 14, 2021 06:43
-
-
Save anmolsukki/5035fe8869b5bd2c4288be59950b6b4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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