Skip to content

ably-forks/react-native-aes

 
 

Repository files navigation

React Native AES

AES encryption/decryption for react-native

Installation

npm install --save @ably/react-native-aes

or

yarn add @ably/react-native-aes

Installation (iOS)

Using CocoaPods (React Native 0.60 and higher)
cd ios
pod install

Usage

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 mode
  • aes-192-cbc - AES-192 in CBC mode
  • aes-256-cbc - AES-256 in CBC mode
  • aes-128-ctr - AES-128 in CTR mode
  • aes-192-ctr - AES-192 in CTR mode
  • aes-256-ctr - AES-256 in CTR mode

About

Native module for AES encryption

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 59.9%
  • Java 36.8%
  • Ruby 2.0%
  • JavaScript 1.3%