# `AshVault.Errors.CiphertextIntegrityFailed`
[🔗](https://github.com/jakeschurch/ash_vault/blob/main/lib/ash_vault/errors.ex#L308)

Raised when the AEAD authentication tag does not verify.

The "authentication" here is the *authenticated* in authenticated encryption: a
cryptographic check that the stored bytes are the bytes AshVault wrote, under the key
and the associated data it wrote them with. Causes are tampering with the stored
ciphertext, decrypting with the wrong key, or decrypting under different associated
data (a different scope, resource or field).

It is **not** an authorization or sign-in failure, and has nothing to do with
`AshAuthentication` or `Ash.Policy.Authorizer`. AshVault performs no authorization at
all; by the time a value reaches the crypto layer Ash has already decided the caller
may have it. This error is named for ciphertext integrity for exactly that reason: an
earlier name borrowed the word "authentication", and read as an access-control error it
gets triaged as a routine permissions problem, when it in fact means someone or
something is writing to your ciphertext columns.

A destroyed key must never surface here: destruction is checked before any decryption
is attempted, and reports `AshVault.Errors.KeyDestroyed`.

# `exception`

```elixir
@spec exception(opts :: Keyword.t()) :: %AshVault.Errors.CiphertextIntegrityFailed{
  __exception__: true,
  bread_crumbs: term(),
  class: term(),
  field: term(),
  key_version: term(),
  path: term(),
  resource: term(),
  splode: term(),
  stacktrace: term(),
  vars: term()
}
```

Create an `Elixir.AshVault.Errors.CiphertextIntegrityFailed` without raising it.

## Keys

- :resource
- :field
- :key_version

---

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