Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Encrypt and decrypt a Text in react native? [closed]

I need store the secure information in AsyncStorage ,

So please any one explain how Encrypt and decrypt a Text in react native

like image 303
Saravana Kumar Avatar asked Mar 16 '17 06:03

Saravana Kumar


1 Answers

You can use crypto-js library https://github.com/brix/crypto-js. Works fine within React Native app.

npm install crypto-js --save

var CryptoJS = require("crypto-js");

var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123');
console.log("encrypted text", ciphertext.toString());

var bytes  = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123');
var plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log("decrypted text", plaintext);
like image 196
vinayr Avatar answered Sep 28 '22 06:09

vinayr