3.2.1 • Published 10 months ago
react-native-aes-crypto v3.2.1
React Native AES
AES encryption/decryption for react-native
Installation
npm install --save react-native-aes-crypto
or
yarn add react-native-aes-crypto
Installation (iOS)
Using CocoaPods (React Native 0.60 and higher)
cd ios
pod install
Using React Native Link (React Native 0.59 and lower)
Run react-native link react-native-aes-crypto
after which you should be able to use this library on iOS.
Installation (Android)
React Native 0.60 and higher
- Linking is done automatically
Using React Native Link (React Native 0.59 and lower)
- In
android/settings.gradle
...
include ':react-native-aes-crypto'
project(':react-native-aes-crypto').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-aes-crypto/android')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':react-native-aes-crypto')
}
- register module (in MainApplication.java)
......
import com.tectiv3.aes.AesPackage;
......
@Override
protected List<ReactPackage> getPackages() {
......
new AesPackage(),
// or
// packages.add(new AesPackage());
......
}
Usage
Demo project
Example
import { NativeModules, Platform } from 'react-native'
import Aes from 'react-native-aes-crypto'
const generateKey = (password, salt, cost, length) => Aes.pbkdf2(password, salt, cost, length, 'sha256')
const encryptData = (text, key) => {
return Aes.randomKey(16).then(iv => {
return Aes.encrypt(text, key, iv, 'aes-256-cbc').then(cipher => ({
cipher,
iv,
}))
})
}
const decryptData = (encryptedData, key) => Aes.decrypt(encryptedData.cipher, key, encryptedData.iv, 'aes-256-cbc')
try {
generateKey('Arnold', 'salt', 5000, 256).then(key => {
console.log('Key:', key)
encryptData('These violent delights have violent ends', key)
.then(({ cipher, iv }) => {
console.log('Encrypted:', cipher)
decryptData({ cipher, iv }, key)
.then(text => {
console.log('Decrypted:', text)
})
.catch(error => {
console.log(error)
})
Aes.hmac256(cipher, key).then(hash => {
console.log('HMAC', hash)
})
})
.catch(error => {
console.log(error)
})
})
} catch (e) {
console.error(e)
}
Or
async function asyncDecrypt(cipher, key, iv) {
try {
var text = await decryptData({ cipher, iv }, key)
console.log(text)
return text
} catch (e) {
console.error(e)
}
}
methods
encrypt(text, key, iv, algorithm)
decrypt(base64, key, iv, algorithm)
pbkdf2(text, salt, cost, length, algorithm)
hmac256(cipher, key)
hmac512(cipher, key)
sha1(text)
sha256(text)
sha512(text)
randomUuid()
randomKey(length)
3.2.1
10 months ago
3.2.0
10 months ago
3.1.0
11 months ago
3.0.3
1 year ago
3.0.2
2 years ago
3.0.1
2 years ago
3.0.0
2 years ago
2.1.1
3 years ago
2.1.0
4 years ago
2.0.0
4 years ago
1.3.10
5 years ago
1.3.9
5 years ago
1.3.8
6 years ago
1.3.7
6 years ago
1.3.6
6 years ago
1.3.5
6 years ago
1.3.4
7 years ago
1.3.3
7 years ago
1.3.2
7 years ago
1.3.1
7 years ago
1.3.0
7 years ago
1.2.1
8 years ago
1.2.0
8 years ago
1.1.0
8 years ago
1.0.19
9 years ago
1.0.18
9 years ago
1.0.17
9 years ago
1.0.16
9 years ago
1.0.15
9 years ago
1.0.14
9 years ago
1.0.13
9 years ago
1.0.12
9 years ago
1.0.11
9 years ago
1.0.10
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago