My CryptoJS encryption/decryption is not working

后端 未结 1 1023
星月不相逢
星月不相逢 2021-02-05 14:06

I have an array of JSON arrays whose values I am trying to encrypt with CryptoJS and then print for use in another file, where these values should be decrypted using a user-give

相关标签:
1条回答
  • 2021-02-05 14:37

    That error message usually means the data wasn't decrypted correctly, and the resulting plaintext bytes don't form valid UTF-8 characters.

    A couple things to check:

    • First, make sure you're using the same password for both encryption and decryption. You may want to keep a hash of the correct password so that you can verify if the user gave the correct password before you use it for decryption.
    • Second, make sure that the value item[key] is a string before encrypting. CryptoJS can't encrypt JSON objects. You'll have to serialize it first.
    0 讨论(0)
提交回复
热议问题