A password manager, a private gallery and an encrypted notes app share one promise: the server stores the data but cannot read it. Keeping that promise takes more than calling an encryption function. You need a way to log in without sending the password. You need to change the password without re-encrypting everything. A record must not be movable to another id. A large file must be encrypted in chunks, and a missing last chunk must be noticed. And you still want to search by email.

Each of these has a known answer, and each is easy to get slightly wrong. e2ee_vault is a small pure Dart toolkit that packages them: an Argon2id key hierarchy, record encryption, a streaming file format that detects truncation, blind indexes, and password tools. It is built on top of package:cryptography.

The README opens with a warning, so this article does too: not audited, review before use in production. The package has not had an independent security audit. It is small on purpose, so you can read all of it. Every algorithm wrapper is checked against official test vectors, and every format has round-trip and tamper tests. That still does not replace a review by someone qualified.

What it does

Key hierarchy. The master password goes through Argon2id with parameters you can configure. HKDF-SHA256 then splits the result into two independent subkeys: an auth hash that you send to the server and which cannot decrypt anything, and a key-encryption key (KEK) that wraps a random 256-bit vault key. Changing the password re-wraps the vault key, and no data is re-encrypted. A recovery key is optional. The KDF parameters live in a versioned header, so you can upgrade them later.

Record encryption. Records use XChaCha20-Poly1305 with random 192-bit nonces. The associated data binds the record id and the record version, so a ciphertext moved to another id or version fails to decrypt. The envelope is versioned binary, or base64url.

Streaming file encryption. This is a STREAM construction: each file gets its own key, the chunk index and a last-chunk flag go in the nonce, and the header is authenticated in every chunk. It detects dropped chunks (final and middle ones), reordered chunks, chunks or headers spliced in from other files, header edits, and truncation anywhere. The API is Stream<List<int>> in and Stream<List<int>> out, and it holds at most one chunk in memory.

Blind index. HMAC-SHA256 tokens with a separate key per field, for exact-match search on encrypted fields.

Password tools. A generator that uses rejection sampling, so there is no modulo bias, and that can exclude ambiguous characters, require character classes and report exact entropy. Diceware passphrases over the embedded EFF large wordlist. An entropy estimate. Vault health checks for weak, reused and old passwords.

HIBP breach check, in package:e2ee_vault/hibp.dart. It sends only the first 5 hex characters of the SHA-1 hash, sets Add-Padding: true, and lets you inject the HTTP client.

A KeyStore interface for storing the keyring. The package has no Flutter dependency, and it works on the VM, AOT, Flutter and the web.

How to use it

Add it from GitHub:

dependencies: e2ee_vault: git: https://github.com/AbdeldjalilChougui/e2ee_vault 

The main flow, shortened from the README example:

import 'dart:convert'; import 'package:e2ee_vault/e2ee_vault.dart'; Future<void> main() async { final manager = VaultKeyManager(); // Argon2id: 19 MiB, t=2, p=1 (OWASP) // Sign-up: store the keyring, send authHash to the server, show the // recovery key once. final created = await manager.createVault('correct horse battery', withRecoveryKey: true); final store = InMemoryKeyStore(); // use a secure-storage adapter in apps await store.saveKeyring(created.keyring); // Unlock. final unlocked = await manager.unlock('correct horse battery', (await store.loadKeyring())!); // Records: bound to id + version. final records = RecordCipher(unlocked.vaultKey); final env = await records.encryptString('{"password":"hunter2"}', recordId: 'item-42', recordVersion: 1); final json = await records.decryptString(env, recordId: 'item-42', recordVersion: 1); // Files: bounded-memory streams (e.g. File.openRead() / openWrite()). final files = FileStreamCipher(unlocked.vaultKey); final ciphertext = files.encrypt(Stream.value(utf8.encode('photo'))); final plaintext = files.decrypt(ciphertext); // Search: exact-match tokens. final byEmail = await BlindIndex.derive(unlocked.vaultKey, field: 'email'); final token = await byEmail.token('alice@example.com'); // Change the password. Data stays as it is; send the new authHash. final changed = await manager.changePassword(created.keyring, currentPassword: 'correct horse battery', newPassword: 'new passphrase'); await store.saveKeyring(changed.keyring); } 

Recovery is two calls:

final vaultKey = await manager.unlockWithRecoveryKey(keyring, RecoveryKey.parse(userInput)); final reset = await manager.setPassword(keyring, vaultKey, newPassword); 

In a Flutter app, you implement KeyStore (three methods: read, write, delete) over flutter_secure_storage. The README has the adapter. It also shows how to upgrade the KDF parameters with needsKdfUpgrade, and example/main.dart runs every feature.

Argon2id parameters and speed

The default preset is Argon2idParams.owasp: 19 MiB, t=2, p=1, the minimum configuration of the OWASP Password Storage Cheat Sheet. Two RFC 9106 presets are also there: 64 MiB, t=3, p=4, and 2 GiB, t=1, p=4. The default is OWASP's because the RFC options are slow in pure Dart on phones.

The README gives the author's own measurement on one development machine (x86-64 Linux, Dart 3.9, AOT): about 0.9 s for Argon2id with the default parameters, about 3.4 s for the 64 MiB preset, and file streaming at about 3 MiB/s. Phones are slower, so measure on your slowest target. In Flutter, adding cryptography_flutter moves ChaCha20-Poly1305 and HMAC to platform code on some platforms, but Argon2id and XChaCha20-Poly1305 are not accelerated by its 2.3.x releases.

Things to know

The README has a full threat model. The short version:

  • The server cannot decrypt, but it can guess offline. Anyone holding a keyring, or an auth hash plus the salt and parameters, can test password guesses at one Argon2id evaluation each. The password and the Argon2id cost are what protect you. Servers should hash the auth hash again before storing it.
  • Tampering is detected, deletion and rollback are not. The server can still delete or withhold records, replay an old record with its old version unless the client tracks the version it expects, or roll back the whole vault to an older consistent state. Detecting that needs a signed or client-held version log, which the package does not include.
  • Metadata leaks. There is no padding, so records leak their exact length and files leak their length rounded to the chunk size. Records that share a value in a field share a blind-index token, which makes frequency analysis possible on low-entropy fields.
  • Streaming output is an authentic prefix until the end. Each chunk is released as soon as it is authenticated. Accept the output only when the stream completes without error. For files, write to a temporary file and rename it.
  • Passwords are not Unicode-normalized. Normalize them yourself (NFC or NFKC) if users type on different platforms.
  • Out of scope: malware on an unlocked device, memory forensics (Dart cannot reliably wipe keys), side channels in the pure-Dart implementations (not evaluated), forward secrecy, multi-user sharing and key commitment.
  • estimateEntropyBits is an upper bound. It overestimates human-chosen passwords: Password1! scores about 66 bits. Combine it with the HIBP check. The vault-health thresholds are product heuristics, not a standard.
  • What was tested. Official vectors run through the package's own wrappers: Argon2id (RFC 9106), XChaCha20-Poly1305 (draft-irtf-cfrg-xchacha-03), ChaCha20-Poly1305 (RFC 8439), HKDF-SHA256 (RFC 5869) and HMAC-SHA256 (RFC 4231). Every format has round-trip and bit-flip tests, and the stream format has one explicit test per attack. The HIBP tests make no network calls.

Why I built it

The README's design section explains what goes wrong without a toolkit like this. Some older chunked AES-GCM formats sealed chunks independently, with a random prefix and a counter and no final-chunk flag, so they could not detect dropped trailing chunks. The common "insert one of each class, then shuffle" password generator is biased. A record cipher without the id in its associated data lets a server swap two ciphertexts.

These are format decisions, and they should be made once, written down byte by byte, and tested against each attack. That is what the package is: a key hierarchy, three binary formats documented to the offset, and a threat model that says what is and is not covered. Small enough to read in full, which matters for code nobody has audited yet.

Get the code

The source, the format tables, the threat model and the tests are on GitHub: https://github.com/AbdeldjalilChougui/e2ee_vault. It is MIT licensed, and the embedded EFF wordlist is CC BY 3.0 US. Review it before you put real secrets behind it.

Originally published at abdeldjalilchougui.biz.