@ably/react-native-aes
v0.0.3
Published
AES crypto native module for react-native
Readme
React Native AES
AES encryption/decryption for react-native
Installation
npm install --save @ably/react-native-aesor
yarn add @ably/react-native-aesInstallation (iOS)
Using CocoaPods (React Native 0.60 and higher)
cd ios
pod installUsage
This library uses React Native TurboModules for optimal performance.
Example
import { encrypt, decrypt } from '@ably/react-native-aes';
async function encryptData() {
try {
// Algorithm name (e.g., 'aes-128-cbc', 'aes-256-cbc', 'aes-128-ctr', 'aes-256-ctr')
const algorithm = 'aes-256-cbc';
// Convert your key, iv, and data to ArrayBuffers
const key = new Uint8Array(32); // 32 bytes for AES-256
const iv = new Uint8Array(16); // 16 bytes for AES IV
const data = new TextEncoder().encode('Hello World');
const encryptedData = await encrypt(
algorithm,
iv.buffer,
key.buffer,
data.buffer
);
console.log('Encrypted:', new Uint8Array(encryptedData));
// Decrypt the data
const decryptedData = await decrypt(
algorithm,
iv.buffer,
key.buffer,
encryptedData
);
const text = new TextDecoder().decode(decryptedData);
console.log('Decrypted:', text);
return text;
} catch (e) {
console.error('Encryption error:', e);
}
}Methods
encrypt(name: String, iv: ArrayBuffer, key: ArrayBuffer, data: ArrayBuffer) => Promise<ArrayBuffer>decrypt(name: String, iv: ArrayBuffer, key: ArrayBuffer, data: ArrayBuffer) => Promise<ArrayBuffer>
Supported Algorithms
aes-128-cbc- AES-128 in CBC modeaes-192-cbc- AES-192 in CBC modeaes-256-cbc- AES-256 in CBC modeaes-128-ctr- AES-128 in CTR modeaes-192-ctr- AES-192 in CTR modeaes-256-ctr- AES-256 in CTR mode
