react-native-crypto-js
react-native-crypto-js copied to clipboard
Error: Malformed UTF-8 data
I used same code for aes encrypt (in Readme file) for my react-native android app and server,
let data = [{id: 1}, {id: 2}] // Encrypt in react-native android app let ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();
// Decrypt in the nodejs server let bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123'); let decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
when my react-native app is in "JS Dev Mode" activated and "JS Minify" desactivated the decryption in the server works fine, but when i configure my app as "JS Dev Mode" desactivated and "JS Minify" activated i cant decrypt the data in the server,
Error: Malformed UTF-8 data at Object.stringify
the error throw in the server only when the app is in production mode, the error happend exactly when execute: bytes.toString(CryptoJS.enc.Utf8)
Can someone explain to me what I am doing wrong or how to solve the problem? please
Please help me, thanks
i have this problem too !
It was working with 0.54. But when upgrading to react-native 0.59.10, I also encounter the same issue.
It seems that the cause is because react-native is trying to minify an already minified file within this package.
I had to replace this package with https://www.npmjs.com/package/crypto-js.
I think, when your app is on debug version or release version or a different react-native version, it encrypt in different ways. I tested this and with same string and same secret key in debug version, i've had a string while in release version i've had a different string
Hello! I can confirm that AES.encrypt/decrypt and MD5 return different outputs on the Expo Client application and published APK/IPA. I noticed this in my secure messaging app while testing with two different phones - the other running debug Expo Client version and the other published APK. The AES encrypted data does not decrypt if created on a different app stage (debug/production) eventhough using the same key.
same problem. how to solve this problem
same problem. how to solve this problem
https://github.com/imchintan/react-native-crypto-js/issues/5#issuecomment-510747872
same problem. how to solve this problem
I'm using Expo so do I have to eject to use this?
I don't know about expo.
I simply removed react-native-crypto-js": "^1.0.0"
from package.json and replace it with "crypto-js": "^3.1.9-1",
. Run npm install
to download the package.
Then change all existing occurences of:
import CryptoJS from 'react-native-crypto-js';
to
var CryptoJS = require('crypto-js');
@rchaviknis it working in release build . Crypto-js
I don't know about expo.
I simply removed
react-native-crypto-js": "^1.0.0"
from package.json and replace it with"crypto-js": "^3.1.9-1",
. Runnpm install
to download the package.Then change all existing occurences of:
import CryptoJS from 'react-native-crypto-js';
to
var CryptoJS = require('crypto-js');
Is this working in realase build for react native.
yes. but i'm on 0.59. not sure about recent react-native, but should be the same.
yes. but i'm on 0.59. not sure about recent react-native, but should be the same.
Yes. This solution works.thanks @rchavik
Working in react-native 0.59.1 also.
Not working with 0.59.5. What to do?
It was working with 0.54. But when upgrading to react-native 0.59.10, I also encounter the same issue.
It seems that the cause is because react-native is trying to minify an already minified file within this package.
I had to replace this package with https://www.npmjs.com/package/crypto-js.
How you installed crypto-js in react native? I would need to do extra configurations?
I have a RN app with 0.71.8