encrypt and decrypt in js code example
Example 1: encrypt and decrypt in nodejs
const Cryptr = require('cryptr');const cryptr = new Cryptr('myTotalySecretKey'); const encryptedString = cryptr.encrypt('bacon');const decryptedString = cryptr.decrypt(encryptedString); console.log(encryptedString);
Example 2: encrypt decrypt in vanilla javascript
var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
document.getElementById("demo1").innerHTML = encrypted;
document.getElementById("demo2").innerHTML = decrypted;
document.getElementById("demo3").innerHTML = decrypted.toString(CryptoJS.enc.Utf8);