Advertisement
Guest User

OpenSSL-compatible CryptoJS Example

a guest
Sep 21st, 2015
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. load( 'rollups/aes.js' );
  2. load( 'components/pad-ansix923.js' );
  3.  
  4. var data = "hello! this is a test!";
  5. var key = '59b6ab46d379b89d794c87b74a511fbd59b6ab46d379b89d794c87b74a511fbd';
  6. var iv = '0aaff094b6dc29742cc98a4bac8bc8f9';
  7.  
  8. var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(data), CryptoJS.enc.Hex.parse(key), { iv: CryptoJS.enc.Hex.parse(iv) });
  9.  
  10. print( 'Ciphertext: [' + encrypted.ciphertext + ']' );
  11. print( 'Key:        [' + encrypted.key + ']' );
  12.  
  13. cipherParams = CryptoJS.lib.CipherParams.create({ciphertext: CryptoJS.enc.Hex.parse(encrypted.ciphertext.toString())});
  14. var decrypted = CryptoJS.AES.decrypt(cipherParams, CryptoJS.enc.Hex.parse(key), { iv: CryptoJS.enc.Hex.parse(iv) });
  15.  
  16. print( 'Cleartext:  [' + decrypted.toString(CryptoJS.enc.Utf8) + ']');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement