How to encrypt and decrypt text in response to native?

I need to save protected information in AsyncStorage ,

Therefore, please explain how to encrypt and decrypt text in the native response

+6
source share
1 answer

You can use the crypto-js library https://github.com/brix/crypto-js . Works fine in 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);
+11
source

Source: https://habr.com/ru/post/1015782/


All Articles