Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var message = "SuperSecret!!";
  2.  
  3. var getKeyAndIV = function(password) {
  4.  
  5. var keyBitLength = 256;
  6. var ivBitLength = 128;
  7. var iterations = 234;
  8.  
  9. var bytesInSalt = 128 / 8;
  10. var salt = CryptoJS.lib.WordArray.random(bytesInSalt);
  11.  
  12. var iv128Bits = CryptoJS.PBKDF2(password, salt, { keySize: 128 / 32, iterations: iterations });
  13. var key256Bits = CryptoJS.PBKDF2(password, salt, { keySize: 256 / 32, iterations: iterations });
  14.  
  15. return {
  16. iv: iv128Bits,
  17. key: key256Bits
  18. };
  19. };
  20.  
  21. var skey = getKeyAndIV("Password01");
  22.  
  23. var data = CryptoJS.AES.encrypt(message, skey.key, { iv: skey.iv }); // , format: JsonFormatter
  24.  
  25. $(".output_text").val(data.ciphertext.toString(CryptoJS.enc.Base64));
  26. $(".output_key").val(data.key.toString(CryptoJS.enc.Base64));
  27. $(".output_iv").val(data.iv.toString(CryptoJS.enc.Base64));
  28.  
  29.  
  30. var ciphertext = CryptoJS.enc.Base64.parse($(".output_text").val());
  31. var key = CryptoJS.enc.Base64.parse($(".output_key").val());
  32. var iv = CryptoJS.enc.Base64.parse($(".output_iv").val());
  33.  
  34. var params = {
  35. ciphertext: ciphertext,
  36. salt: ""
  37. };
  38.  
  39. var clearText = CryptoJS.AES.decrypt(params, key, { iv: iv });
  40.  
  41. $(".output2").val(clearText.toString(CryptoJS.enc.Utf8));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement