aes256 2.2.0
aes256: ^2.2.0 copied to clipboard
AES-256 encryption and decryption using PBKDF2 + AES-GCM.
๐ AES256 #
A lightweight, modern, and secure AES-256-GCM encryption library for Dart & Flutter.
Designed with strong defaults, clean APIs, and seamless usability across mobile, web, and server environments.
๐ Live Demo: https://knottx.dev/aes256
๐ Features #
- AES-256-GCM โ Authenticated encryption with integrity protection
- PBKDF2-HMAC-SHA256 โ Strong password-based key derivation
- 100,000 iterations โ Secure default against brute-force attacks
- Random salt & nonce โ Automatically handled
- Stateless API โ Easy to integrate into any architecture
- Pure Dart โ Works on Flutter, Dart VM, and Web
๐ง Usage #
import 'package:aes256/aes256.dart';
void main() async {
// Encrypt
final encrypted = await Aes256.encrypt(
text: 'Hello world',
passphrase: 'my-passphrase',
);
// Decrypt
final decrypted = await Aes256.decrypt(
encrypted: encrypted,
passphrase: 'my-passphrase',
);
print(decrypted); // Hello world
}
๐ How It Works #
AES256 outputs a structured, self-contained binary payload:
salt(16) + nonce(12) + ciphertext + tag
Security Parameters #
| Component | Value |
|---|---|
| Cipher | AES-256-GCM |
| Key Derivation | PBKDF2-HMAC-SHA256 |
| Iterations | 100,000 |
| Salt | 16 bytes (random, public) |
| Nonce | 12 bytes (random, public) |
| Auth Tag | 16 bytes |
| Integrity | Built-in (GCM tag) |
Why salt & nonce are public #
Salt and nonce do not provide secrecy by themselves โ they ensure uniqueness and key strengthening.
The passphrase-derived key is the only secret.
Exposing salt/nonce does not weaken the encryption.
๐งช Example Output (Base64) #
QTI1NkdDTQEBEBcAAAAAAAAAACZ1FqvXโฆ(ciphertext)โฆLk5h0nA=
๐ก๏ธ Security Notes #
- Always use a strong passphrase
- AES-GCM requires a unique nonce per encryption โ this library handles it automatically
- For high-security systems, keep actual keys in secure storage or server-side only
โ FAQ #
Is the encrypted output safe to store publicly? #
Yes โ as long as the passphrase remains secret.
Can I decrypt data encrypted in another language? #
Yes โ as long as the other implementation uses the same payload structure and AES-256-GCM + PBKDF2-SHA256 parameters.
This library follows a clean and predictable binary format:
salt(16) + nonce(12) + ciphertext + tag
Any implementation that generates output in the same sequence will decrypt correctly.
Does it work on Flutter Web? #
Yes โ it is pure Dart with no native bindings.