Skip to content

Instantly share code, notes, and snippets.

Created March 14, 2018 17:23
Show Gist options
  • Save anonymous/90eff80b090960080dd642b7423d78ce to your computer and use it in GitHub Desktop.
Save anonymous/90eff80b090960080dd642b7423d78ce to your computer and use it in GitHub Desktop.
CryptoJS AES Encryption (source: https://jsfiddle.net/beL4q171/12/)
<p>Message: <span id="message"></span>
</p>
<p>Encrypted: <span id="1"></span>
</p>
<p>Decrypted text: <span id="2"></span>
</p>
var key = CryptoJS.enc.Hex.parse('0123456789abcdef');
var iv = CryptoJS.enc.Hex.parse('fedcba9876543210');
var message = "fubar";
var encrypted = CryptoJS.AES.encrypt(message, key, {
iv: iv
});
var decrypted = CryptoJS.AES.decrypt(
'IKcST4CbRgw5ipEZv+zaug==', key, {
iv: iv
}).toString(CryptoJS.enc.Utf8);
$('#message').text('"' + message + '" ');
$('#1').text(encrypted);
$('#2').text(decrypted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment