My encryption / decryption CryptoJS does not work

I have an array of JSON arrays whose values ​​I'm trying to encrypt using CryptoJS and then print for use in another file, where these values ​​must be decrypted using a custom passphrase.

But I'm doing something wrong, and when decrypting the URL, I get the error message "Fault: invalid UTF-8 data."

encrypt.js:

var encrypted = CryptoJS.AES.encrypt(item[key], pass);
json[j] += encrypted.ciphertext.toString(CryptoJS.enc.Base64);

decrypt.js:

var decrypted = CryptoJS.AES.decrypt(item[key], pass);
html += '<a href="' + decrypted.toString(CryptoJS.enc.Utf8) + '" target="_blank" class="socialico ' + key + '">' + icons[key] + '</a>';

I followed this example ... Help, please, please?

+5
source share
1 answer

This error message usually means that the data has not been decrypted correctly, and the resulting unallocated bytes do not form valid UTF-8 characters.

:

  • , . , , , , .
  • -, , item[key] . CryptoJS JSON. .
+11

All Articles