Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto.js throws Malformed UTF-8 data #12

Open
spammads opened this issue Feb 22, 2024 · 3 comments
Open

crypto.js throws Malformed UTF-8 data #12

spammads opened this issue Feb 22, 2024 · 3 comments

Comments

@spammads
Copy link

When providing the correct passwords I get an exception on

var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
          iv: iv,
          padding: CryptoJS.pad.Pkcs7,
          mode: CryptoJS.mode.CBC
        }).toString(CryptoJS.enc.Utf8);
        return decrypted;

saying

Malformed UTF-8 data

According to this comment maybe it helps to convert encrypted to string

@blairanderson
Copy link
Owner

can you confirm the fix or send me a link to try it out?

@jjsmck
Copy link

jjsmck commented Mar 6, 2024

Hi

I am also get this error. However I am using a string value
let encrypted = "add_your_encrypted_value"
let key = "1234567890123456789012"
let ivValue = "add_iv_value"
let iv = CryptoJS.enc.Utf8.parse(ivValue)
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
iv: iv,
padding: CryptoJS.pad.Pkcs7,
mode: CryptoJS.mode.CBC
}).toString(CryptoJS.enc.Utf8);

error : Malformed UTF-8 data

The issue so far that I can tell is that encrypted contains symbol. It be nice for the CryptoJS.enc.Utf8, to check for the symbols and remove it.

@toiladuong
Copy link

You can consider my solution here:
https://github.com/brix/crypto-js/issues/271#issuecomment-2342530158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants