forked from firka/firka
966 B
966 B
FMBCrypt Dart Library 5
Pretty easy to install and secure, I think...
Usage:
Encryption:
await FMBCrypt.handleText('encrypt', plaintext, password);
Decryption:
await FMBCrypt.handleText('decrypt', ciphertext, password);
Under the hood
Key generation
- Generates a random 32-byte salt
- Convert password into bytes with UTF-8 encoding
- PBKDF2 the password (SHA-512, 1,000,000x, 256 bits, salt)
- Secure the final 32-byte key
Encryption
- Generates a 12-byte nonce for GCM
- Creates associated data (application ID + version + salt + timestamp) for authentication
- Sets up AES-256 in GCM mode (authenticated encryption)
- Encrypt bytes using AES-GCM with associated data
- Combine the data in the following order:
- First 4 bytes: Version header ("FMB5")
- Next 32 bytes: Salt
- Next 8 bytes: Timestamp
- Next 12 bytes: GCM Nonce
- Remaining: Encrypted data + 16-byte authentication tag