V
V
VladimirSX2020-10-30 23:35:27
Encryption
VladimirSX, 2020-10-30 23:35:27

How to use "react-native-aes-cipher" library?

Specify the variables where you want to put the data and what data, and where the encryption result will be located. How to decipher this result?
Preferably with a proven working code, which will have a field for input and output of data
with comments!

npm install --save react-native-aes-cipher

import { NativeModules, Platform } from 'react-native'
var Aes = NativeModules.Aes

const generateKey = (password: string, salt: string, cost: number, length: number) => Aes.pbkdf2(password, salt, cost, length)

const encryptData = (text: string, key: any) => {
    return Aes.randomKey(16).then((iv: any) => {
        return Aes.encrypt(text, key, iv).then((cipher: any) => ({
            cipher,
            iv,
        }))
    })
}

const encryptDataIV = (text: string, key: any, iv:any) => {
  return Aes.encrypt(text, key, iv).then((cipher: any) => ({
    cipher,
    iv,
  }))      
}

const decryptData = (encryptedData: { cipher: any; iv: any; }, key: any) => Aes.decrypt(encryptedData.cipher, key, encryptedData.iv)
const iv_string = '0123456789abcdef0123456789abcdef';

let encrypt_key:any = "";
let encrypt_string:any = "";
let plain_string:any = "1234567890";
let encrypt_iv:any = "";


Link to the library: https://github.com/reactspring/react-native-aes-cipher

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question