# `AshVault.Encrypted`
[🔗](https://github.com/jakeschurch/ash_vault/blob/main/lib/ash_vault/encrypted.ex#L1)

One encrypted field of a resource — the target struct of the `encrypt` DSL entity.

    ash_vault do
      vault MyApp.Vault
      encrypt :email
      encrypt :ssn, encrypt_nil?: false
    end

`:encrypt_nil?` is `nil` here when the field does not override the section-level
setting; `AshVault.Info.encrypt_nil?/2` resolves the effective value.

`:searchable?` adds a deterministic `<name>_lookup` token column; `:unique?` puts a
unique identity on it; `:normalize` decides what "equal" means for both. See
`AshVault.Lookup`.

`:pre_check_with` is the domain to check that identity against in a `before_action`
hook, for a data layer that cannot enforce uniqueness itself. Required there, refused
nowhere, and off by default everywhere — it costs a read on every write.

`:stored_as` fixes the ciphertext storage and cryptographic binding identity without
changing the logical name. It defaults to the logical name for ordinary encryption.
`:legacy` and `:decrypt_for` also support expand mode; see `AshVault.Dsl`.
`AshVault.Info.encrypted_fields/1` presents a `legacy:` entity as the field that is
actually encrypted — named `stored_as`, with `backfill_from` the legacy attribute and
`:legacy_of` naming it — so the write path, the backfill and the key tooling treat it
like any other encrypted field.

# `t`

```elixir
@type t() :: %AshVault.Encrypted{
  __spark_metadata__: term(),
  backfill_from: atom() | nil,
  decrypt_for: [term()] | nil,
  encrypt_nil?: boolean() | nil,
  legacy: module() | {module(), keyword()} | nil,
  legacy_of: atom() | nil,
  name: atom(),
  normalize: AshVault.Lookup.normalize(),
  pre_check_with: module() | nil,
  searchable?: boolean(),
  stored_as: atom() | nil,
  unique?: boolean()
}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
