Skip to content

Instantly share code, notes, and snippets.

@kaosf
Created June 19, 2014 12:39
Show Gist options
  • Save kaosf/28b06a7cec92c9eaa648 to your computer and use it in GitHub Desktop.
Save kaosf/28b06a7cec92c9eaa648 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>
var secretPassphrase = "passphrase";
var encryptedString = CryptoJS.AES.encrypt("message", secretPassphrase).toString();
console.log(encryptedString); //=> e.g. "U2FsdGVkX193mDQv3nToLW9SDrjntBZoS2uZd6XBeVM" // It's not stable. Why?
var message = CryptoJS.AES.decrypt(encryptedString, secretPassphrase).toString(CryptoJS.enc.Utf8);
console.log(message); //=> "message"
// ref.
// https://code.google.com/p/crypto-js/#AES
// http://stackoverflow.com/a/22601457/1006253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment