-
-
Save sandeepsuvit/1e712d001a304740f611e9e62a8c0e73 to your computer and use it in GitHub Desktop.
CryptoJS AES Encryption (source: https://jsfiddle.net/beL4q171/12/)
This file contains hidden or 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
<p>Message: <span id="message"></span></p> | |
<p>Encrypted: <span id="encrypted-text"></span></p> | |
<p>Decrypted text: <span id="decrypted-text"></span></p> |
This file contains hidden or 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 key = CryptoJS.enc.Hex.parse('0123456789abcdef'); | |
var iv = CryptoJS.enc.Hex.parse('fedcba9876543210'); | |
var message = "fubar"; | |
// For encrypting | |
var encrypted = CryptoJS.AES.encrypt(message, key, { | |
iv: iv | |
}); | |
// For decrypting | |
var decrypted = CryptoJS.AES.decrypt( | |
{ | |
ciphertext: CryptoJS.enc.Base64.parse(encrypted.toString()), | |
salt: "" | |
}, | |
key, | |
{ | |
iv: iv | |
} | |
).toString(CryptoJS.enc.Utf8); | |
$('#message').text('"' + message + '" '); | |
$('#encrypted-text').text(encrypted); | |
$('#decrypted-text').text(decrypted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment