Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Last active August 29, 2015 14:08
Show Gist options
  • Save mbbx6spp/843f7a9211ed6512efd5 to your computer and use it in GitHub Desktop.
Save mbbx6spp/843f7a9211ed6512efd5 to your computer and use it in GitHub Desktop.
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
function mkCipher(cipherModule, encoding) {
var that = this;
that.encrypt = cipherModule.encrypt;
that.decrypt = function (data, passphrase) {
var decrypted = cipherModule.decrypt(data, passphrase);
return decrypted.toString(encoding);
};
return that;
}
(function () {
var AES = mkCipher(CryptoJS.AES, CryptoJS.enc.Utf8);
var data = "My secret message";
var passphrase = "booyah!";
var encrypted = AES.encrypt(data, passphrase);
alert("Encrypted: " + encrypted);
alert("Decrypted: " + AES.decrypt(encrypted, passphrase));
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment