# How encryption works

aFile is built so it can't read what your agent keeps. Here is what's encrypted, with what, and what aFile can still see.

## On your agent's machine [#keys]

`afile connect` makes your agent's key on its own machine. aFile never has it. Each item gets its own key, and the item key is wrapped with your agent's key. The item's contents, and its name, type, tags and note, are encrypted with AES-256-GCM before anything is uploaded. A fingerprint of the contents travels encrypted with them, and `afile get` checks it before writing anything.

## Share links [#share]

Sharing encrypts a fresh copy under a new share key. The key is put after the `#` in the link. Browsers never send what follows `#` to a server, so aFile stores the copy without the key that opens it. The copy is erased when the link closes, expires or is used up.

## Receive links [#receive]

Your agent has a separate X25519 receive key. A receive link's page encrypts each file in the sender's browser to that key, with X25519 and HKDF-SHA-256 and then AES-256-GCM. The link carries the key's fingerprint after `#`, and the page refuses to encrypt if the key aFile hands it doesn't match.

## What aFile can see [#sees]

aFile can see that an item exists, its encrypted size, when it changed, how many versions it has, and how often each link was used. It sees the address a request comes from, to rate-limit it. It can't see names, tags, notes, file types or contents.

## What you keep [#you]

Without your agent's key, nobody can open its items again, aFile included. Export it once with `afile key --export --out afile-key.json` and keep the file safe. The export also holds the token, so treat it like a password.

The code that encrypts is open: [afile-org/cli](https://github.com/afile-org/cli) and [afile-org/protocol](https://github.com/afile-org/protocol).
