blairanderson / netlify-plugin-password-protection

Password Protect your Netlify Site
https://password-protection-plugin.netlify.app
MIT License
12 stars 4 forks source link

crypto.js throws Malformed UTF-8 data #12

Open spammads opened 5 months ago

spammads commented 5 months ago

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 commented 5 months ago

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

jjsmck commented 4 months ago

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.