danang-id / simple-crypto-js

Simplified AES cryptography for safer and easier encryption and decryption processes of any JavaScript objects.
https://simplecrypto.js.org
MIT License
85 stars 27 forks source link

Malformed UTF-8 data #6

Closed ronastlelobo closed 4 years ago

ronastlelobo commented 5 years ago

I am reading a .mp4 file and encrypting it using the library and writing it as a .dat file. I am accessing the .dat file and streaming 4,000,000 characters at a time till the end. While streaming, i am decrypting the data on go. So, the first set of characters are decrypting succcessfully using this method

var decipherText = simpleCrypto.decrypt(chunk)

while the next set of characters throw Malformed UTF-8 data error.

cptn-solo commented 5 years ago

almost same here - encrypting private keys (ASCII) and get 1 time of each ~5 malformed utf-8 data while trying to decrypt

danang-id commented 5 years ago

@ronastlelobo @kkrupovich I'm sorry for very late response. If you may, could you provide the steps to recreate the case? This may be a bug on byte arrays parsing when decrypting.

paulocastellano commented 5 years ago

@danang-id

I have same problem:

JSON:

{"user_id":"127382173821","user_name":"Paulo","user_email":"paulo@gmail.com","user_avatar":"https://link.to.user.avatar.com/image.jpg","custom_data":{"Job_Role":"CEO","Plan":"Pro","teammates":"4","Monthly_Spend":"50 USD"}}

How i encrypt:

let simpleCrypto = new SimpleCrypto(process.env.SECRET_KEY);
let uri = simpleCrypto.encrypt(JSON.stringify('MY_JSON_HERE'));

update I solve problem with encodeURIComponent and decodeURIComponent.

Kwaysi commented 5 years ago

Thanks encodeURIComponent worked for me too.

irfannurzaman commented 4 years ago

why can't encrypt in local storage be decrypted?

useEffect(() => { let data = localStorage.getItem("localStorage"); if (data) { console.log("localStorage", simpleCrypto.decrypt(data).toString()); } }, []);

danang-id commented 4 years ago

@irfannurzaman Please make sure the data you are trying to get is an actual ciphered text. Otherwise, please open a new issue and provide a technical details or any log about the error.

I'll close the issue for now since it has been solved for a while.