react-native-aes-lite
v1.0.9
Published
AES encryption for React Native + Expo Web
Maintainers
Readme
📦 react-native-aes-lite
Lightweight AES encryption/decryption utility for React Native and Expo. No native modules, no linking — just pure JavaScript.
📖 Overview
react-native-aes-lite provides simple AES block-based text encryption and decryption using a 128-bit key. It is ideal for app-side data scrambling, offline encoding, demos, and educational use.
✔ Encrypt text → hex
✔ Decrypt hex → text
✔ Generate AES keys
✔ Works offline
✔ No native dependencies
✔ React Native CLI support
✔ Expo app support
✔ Expo web support
🚨 Security Warning
This library is not suitable for securing sensitive data.
It does not implement:
- IV / salt
- AES-GCM
- AES-CBC
- key derivation
- authenticated encryption
- secure storage
If you need production-grade crypto → use a native AES solution.
📦 Install
npm install react-native-aes-liteor
yarn add react-native-aes-lite🚀 Usage
import { AES, generateKey } from "react-native-aes-lite";
const aes = new AES();
const key = generateKey("hex", { length: 16 });
const encrypted = aes.encrypt("hello world", key);
console.log("Encrypted:", encrypted);
const decrypted = aes.decrypt(encrypted, key);
console.log("Decrypted:", decrypted);Example output:
Encrypted: f52066d59d6c581c3918e652efe8cb45
Decrypted: hello world🔑 Key Generation
const key = generateKey("hex", { length: 16 });Formats supported:
- hex (recommended)
- base64
- ascii
Key lengths:
- 16 bytes (AES-128)
- 24 bytes (AES-192)
- 32 bytes (AES-256)
📘 API Reference
class AES
new AES()
encrypt(text: string, key: string): string
decrypt(cipherHex: string, key: string): stringgenerateKey(format?, options?)
generateKey(
format?: "hex" | "base64" | "ascii",
options?: { length?: number; readable?: boolean }
): string📌 Example: Saving encrypted text
const aes = new AES();
const key = generateKey("hex");
const token = "USER_SESSION_XYZ";
const encrypted = aes.encrypt(token, key);
await AsyncStorage.setItem("token", encrypted);
const stored = await AsyncStorage.getItem("token");
const decrypted = aes.decrypt(stored, key);⚡ Performance Notes
AES operations are synchronous.
Works best for short strings.
| Device | Speed | |--------|-------| | New iOS / Android | fast | | Mid-range phones | good | | Old hardware | slower |
Not recommended for large blobs.
🧭 Roadmap
Planned:
- AES-256 support
- Async API
- CBC mode
- IV generation
- UTF-8 optimization
- bundle size reduction
Not planned:
- secure storage
- authenticated encryption
- native rewrite
🧩 Platform Support
| Platform | Status | |------------------|--------| | React Native CLI | ✅ | | Expo app | ✅ | | Expo web | ✅ | | Expo Snack | ❌ (npm modules unsupported) | | TypeScript | ⚠ static warnings may appear |
⚠ Expo Snack
Expo Snack does not support npm installation, so this package cannot run inside Snack. Use Expo locally instead:
expo start🐞 Troubleshooting
Error: AES is not a constructor
Use default import fallback:
import aesKit from "react-native-aes-lite";
const { AES } = aesKit;TS2305 — generateKey missing
Ensure latest version is installed.
📜 License
MIT © 2025 Ammachi
