Category Archives: Development

react-native crypto-js aes decrypt problem and solution

CryptoJS is a popular encrypt/decrypt library used by JS community. However, the latest version 4.x.x just can’t be used on react-native. It will need native crypto library as base. Since react-native doesn’t have the native crypto library supported by now, it’s not so easy to get it working on react native platform.

For my project on-going, I need the AES encrypt/decrypt part to work on react native. It will be very useful if CryptoJS could work on it.

While searching the solution to this problem, react-native-crypto-js library has jumped into my sight. From the github repo shown, this library just packaged the crypto-js v3.1.2 from source and register it into npm registry. After some testing, I found it can’t decrypt my encrypted source correctly. The final decrypted result will always stop at some ending point before the real end. Around 10-20 bytes are cut out after decryption.

Then I try to go back to crypto-js github to see the version tag. Fortunately, there still exists version 3.1.x and be registered in npm. For now it’s version 3.1.8. Version 4.x have breaking changes and version 3.x still keep the original source level dependency for encryption/decryption.

As a result, I then tried to install version 3.1.8 to react-native project. And it really worked. The original crypto-js code can work perfectly on react-native project. No more native crypto library dependency required.

If you have the same problems on react-native crypto-js support, try to install version 3.1.x to your project. Simple encryption/decryption will be ready to work.

Happy Coding!