An encrypted field.
field :ssn, Strongbox.Encrypted, vault: MyApp.Vault, redact: true
field :notes, Strongbox.Encrypted, vault: MyApp.Vault, as: :map, redact: true
field :born_on, Strongbox.Encrypted, vault: MyApp.Vault, as: :date, redact: trueThe column is :binary in migrations (bytea in PostgreSQL), or
:text with encoding: :base64.
Pass redact: true, or use Strongbox.Schema, which always does: else
the decrypted value shows when the struct is inspected, in logs and in
error reports.
Options
:vault- the vault, a module that usesStrongbox. Required.:as- what the field holds::binary(the default, any binary),:string(valid UTF-8),:integer,:float,:decimal,:boolean,:date,:time,:naive_datetime,:utc_datetime,:map,{:array, :string}or{:array, :integer}. Maps and lists are kept as JSON, so a map's keys load as strings, as with Ecto's:map.:context- the binary each value is bound to. By default, the field's name: a value copied into another field (ssnintonotes) no longer decrypts there. Give it to keep values readable when the field is renamed:context: "ssn".falsebinds values to nothing, asEcto.Encryptedand Cloak do.:pad- a block size, such as16or64: each value is padded to a multiple of it before it is encrypted, so its length shows only to the block. Use it for fields with few values ("yes","no") or whose length tells something.:encoding-:raw(the default) keeps the encrypted bytes as they are, in a binary column.:base64keeps them as text: for a:textcolumn, and for fields of embedded schemas kept as JSON.
Querying
Each value is encrypted with a random salt, so the same value never
encrypts twice the same way, and where: u.ssn == ^ssn matches nothing.
To look a value up, keep a blind index of it beside it:
Strongbox.Index.