Skip to content

Instantly share code, notes, and snippets.

@coturiv
Last active July 21, 2020 11:03
Show Gist options
  • Select an option

  • Save coturiv/40467ee5753c85a72d0980e47ac7859f to your computer and use it in GitHub Desktop.

Select an option

Save coturiv/40467ee5753c85a72d0980e47ac7859f to your computer and use it in GitHub Desktop.
AES Encryption
const iv = CryptoJS.enc.Base64.parse("101112131415161718191a1b1c1d1e1f");
const encrypt = (message = '', key = '') => {
const encrypted = CryptoJS.AES.encrypt(message, key, {iv}).toString();
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(encrypted));
}
const decrypt = (message = '', key = '') => {
const decrypted = CryptoJS.enc.Base64.parse(message).toString(CryptoJS.enc.Utf8);
return CryptoJS.AES.decrypt(decrypted, key, {iv}).toString(CryptoJS.enc.Utf8)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment