Package Exports
- react-native-aes-256
- react-native-aes-256/lib/commonjs/index.js
- react-native-aes-256/lib/module/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-aes-256) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-native-aes-256 Library
This React Native library provides a secure and convenient way to encrypt and decrypt data using the industry-standard AES-256 algorithm. It seamlessly integrates with your React Native application, allowing you to protect sensitive information on both Android and iOS platforms.
Key Features:
- Robust AES-256 Encryption: Leverages the highly secure AES-256 encryption algorithm for reliable data protection.
- Native Module Integration: Utilizes a native module for enhanced performance and platform-specific security features.
- Simplified API: Offers a user-friendly API with functions for encryption, decryption, and secure key/IV generation.
- Error Handling: Includes error checking for invalid key and IV lengths, preventing potential issues.
Installation
Dependency Installation: Install the library using npm or Yarn:
npm install react-native-aes-256
yarn add react-native-aes-256
Platform-Specific Linking:
- iOS: Run
pod install
in your iOS project directory. - Android: Rebuild your app after installing the package.
- iOS: Run
Usage
Import the functions:
import { encrypt, decrypt, generateSecureKey, generateSecureIV } from 'react-native-aes-256';
Encryption:
// Optional you can use any 32 character string const secureKey = await generateSecureKey('your_password'); // Optional you can use any 16 character string const iv = await generateSecureIV('another_password'); const encryptedData = await encrypt(secureKey, iv, 'your_data_to_encrypt');
Decryption:
const decryptedData = await decrypt(secureKey, iv, encryptedData);
API Reference
encrypt(secureKey: string, iv: string, toBeEncrypted: string): Promise<string>
: Encrypts a string using the provided key and IV.decrypt(secureKey: string, iv: string, toBeDecrypted: string): Promise<string>
: Decrypts a string using the provided key and IV.generateSecureKey(password: string): Promise<string>
: Generates a secure key from a password.generateSecureIV(password: string): Promise<string>
: Generates a secure initialization vector (IV) from a password.
Error Handling
- The
encrypt
anddecrypt
functions reject promises with informative error messages if the key or IV lengths are invalid. - The
IV
length should be 16 - The
SecrueKey
length should be 32
Security Considerations
- Always store keys and IVs securely. Avoid hardcoding them in your code.
Example
A basic example of encrypting and decrypting data can be found in the example folder.
License
This library is licensed under the (MIT License).