DVFieldCipher class

AES-256-GCM over a server-held keyring, for model fields stored in a database.

Separate from DVAppKeyCipher because the threat models do not overlap. That key belongs to one device and is held by the OS key store of the person using it; this one belongs to a server process and protects rows that many people's requests read. Handing either job to the other key is how a device key ends up in a shared database, or a server key in an application bundle.

The column and the model name are authenticated alongside the value, so a ciphertext copied into a different column, or into the same column of a different model's table, fails to open rather than decrypting into a place it was never written for. It does not bind the row: an attacker who can write to the database can still swap two rows' values within one column, and stopping that needs a per-row identity that survives an update, which a generated model does not currently have.

Constructors

DVFieldCipher(DVFieldKeyring keyring, {Random? random})
random is for tests that need a repeatable nonce, and for nothing else.
DVFieldCipher.secure(DVFieldKeyring keyring)
The cipher an application uses: nonces from the platform's secure source, with no way to ask for anything else.

Properties

hashCode → int
The hash code for this object.
no setterinherited
keyring → DVFieldKeyring
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

decrypt({required String model, required String field, required String ciphertext}) → String
Opens a value written by encrypt for the same model and column.
encrypt({required String model, required String field, required String plaintext}) → String
Seals plaintext as dvf1:<key id>:<base64 nonce||ciphertext>.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

macBits → const int
nonceBytes → const int
96 bits, the nonce size AES-GCM is specified for.
prefix → const String
Version tag. A stored value carries it so a future format can be told apart from this one rather than being fed to the wrong reader.