# Crypto-shredding

> Destroy a key, and every secret sealed under it becomes unreadable for good, in every copy and every database backup.

Deleting data from a database leaves it in replicas and backups. Destroying the key it was sealed under makes every
copy unreadable at once, with nothing to find and delete. The store does this for you whenever a user or a group is
deleted, and a realm administrator can do it for the realm's own vault.

## Before you begin

- **Who:** for a user's or a group's key, whoever deletes the user or group; it happens for them. For the realm's
  secrets key, a realm administrator holding `RealmOwner` in this realm or in a realm above it. See
  [Delegated administration](/platform/realms/delegated-administration/).
- **Where:** the API. There are no screens yet.
- **First:** hand over anything others still need. Nothing sealed under a destroyed key can be opened again.

## How it works

| Destroyed | When | What can't be opened again |
|---|---|---|
| A user's own key | the user is deleted | every secret in their personal vault, every version and label |
| A group's own key | the group is deleted | every secret in the group's vault |
| The realm's secrets key | a realm administrator destroys it | every secret in the realm's vault, and every one-time share not yet read |

Each destruction removes every version of the key, and reaches every copy of the database at once: on every site and
in every database backup, since none of them can be opened without the key.

## Set it up

A user's and a group's keys are destroyed for you when they are deleted. See
[Deleting an owner](/secrets-store/vaults/owner-deletion/).

To destroy the realm's secrets key, as a realm administrator ([Call the API](/develop/api/) shows how to get
`$CVYUH_SESSION`):

```sh
curl -X DELETE "https://foobar.cvyuh.com/api/v0/am/keys/v1/secrets/encryption?shred=true" \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

The realm answers `200` with the versions destroyed.

## What users see

After the realm's secrets key is destroyed, every call to the realm's vault answers `503`, saying the realm has no
secrets key. So does making or reading a one-time share, from any vault, since shares are sealed under the realm's
key too. Users' and groups' own vaults, and grants on them, go on working.

## When it fails

| Answer | When | What to do |
|---|---|---|
| `400` | `?shred=true` is missing: the call is refused so it can't be made by mistake | Add `?shred=true` if you mean it |
| `403` | The caller isn't a realm administrator of this realm or a realm above | Ask someone holding `RealmOwner` |

## Limits and defaults

| Limit | Value |
|---|---|
| Undo | none |
| Versions destroyed | every version of the key, at once |
| One version alone | not possible; [Key rotation](/secrets-store/keys-and-protection/key-rotation/) adds versions, and a shred takes them all |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The realm's vault answers `503` | Its key was destroyed | Expected after a shred. Nothing sealed under it opens again |
| One-time shares answer `503` from every vault | They are sealed under the realm's secrets key | Use [grants](/secrets-store/sharing/grants/) to hand secrets on while the realm has no secrets key |

## Audit record

The destruction of a deleted user's or group's key is a `DELETED` change record on the realm's audit trail, made by
the store. Destroying the realm's secrets key isn't on the realm's audit trail yet: keep your own record of when and
why you did it. See [Secrets audit trail](/secrets-store/keys-and-protection/audit-trail/).

## Good to know

- **It can't be undone.**
- **Secrets only.** The realm's other data is sealed under a different key and is untouched.
- **Users' and groups' vaults are under their own keys,** and go on working after the realm's key is destroyed.
- **How the platform's own backups treat a destroyed key isn't published yet.** See
  [Known limitations](/reference/known-limitations/#secrets-store).

## Related

- [Shred a realm's secrets](/secrets-store/guides/shred-a-realms-secrets/): the task, start to finish.
- [Deleting an owner](/secrets-store/vaults/owner-deletion/): what else goes when a user or a group is deleted.
- [Key rotation](/secrets-store/keys-and-protection/key-rotation/): replace a key without losing anything.
