I'm trying to simply encrypt a message using a given key and iV. I've tried several libraries to achieve this but Expo isn't compatible with any of them. I couldn't find any encryption libraries for Expo (That support AES). I guess my question is : How do I encrypt data in React Native running Expo
Ps : I am not interested in expo-crypto
the crypto in this boxThe goal of this module is to reimplement node's crypto module so that it can run in react-native supported environments. Here is the subset that is currently implemented: createHash (sha1, sha224, sha256, sha384, sha512, md5, rmd160) createHmac (sha1, sha224, sha256, sha384, sha512, md5, rmd160)
To encrypt and decrypt data, simply use encrypt() and decrypt() function from an instance of crypto-js. var bytes = CryptoJS. AES. decrypt(ciphertext, 'my-secret-key@123');
Another possibility (what I did) is to use the CryptoES library.
https://www.npmjs.com/package/crypto-es
After long search I found it, it is a continued development of the 3.1 version of the CryptoJS library and can be used with Expo.
npm i --save crypto-es crypto-js
import CryptoES from "crypto-es";
Then you should encrypt the text, for example:
var mytexttoEncryption = "Hello"
const encrypted = CryptoES.AES.encrypt(mytexttoEncryption ,"your password").toString();
var C = require("crypto-js");
var Decrypted = C.AES.decrypt(E, "your password");
var result =Decrypted.toString(C.enc.Utf8);
console.log(result)
Use [email protected] , 3.1.x version use Math.random() and doesn't require node "crypto" package. It's not as safe as the latest version but works for me.
yarn add [email protected]
I only use it for decrypting. If you really need it for some security requirements I suggest you encrypt it in server node enviroment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With