Advertisement
krot

AES encrypt

Jun 7th, 2019
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
  2. function AESencrypt(str,KEY,IV) {
  3.     key = CryptoJS.enc.Utf8.parse(KEY);
  4.     var iv= CryptoJS.enc.Utf8.parse(IV);
  5.     var encrypted = CryptoJS.AES.encrypt(str, key, {iv:iv,  mode: CryptoJS.mode.CBC });
  6.     return encrypted.toString();
  7. }
  8. function AESdecrypt(str,KEY,IV) {
  9.     var key = CryptoJS.enc.Utf8.parse(KEY);
  10.     var iv=    CryptoJS.enc.Utf8.parse(IV);
  11.     var decrypted = CryptoJS.AES.decrypt(str,key,{iv:iv, mode: CryptoJS.mode.CBC});
  12.     return decrypted.toString(CryptoJS.enc.Utf8);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement