TExcelTAD

age: Simple File Encryption

age (pronounced like the Italian aghe) is a small file-encryption tool and format by Filippo Valsorda: no configuration, no key servers, no web of trust, just keys and files. It replaces most of what teams used to do with GPG for secrets, and it is the recommended key type for SOPS.

Concept Looks like
identity (private key) AGE-SECRET-KEY-1… in a key file
recipient (public key) age1…, 62 characters, safe to share and commit
encrypted file binary, starts with the header age-encryption.org/v1; -a gives ASCII armor

Under the hood a file is encrypted with a random file key (ChaCha20-Poly1305), and the file key is wrapped once per recipient with X25519, the same envelope idea as transit data keys.

Note: keys are generated fresh in every session, so the sessions print their shape and never the keys or ciphertext themselves. Do the same in real logs.

Keys, encrypt, decrypt

bash · try it yourself
umask 077
age-keygen -o ada.key 2> /dev/null
age-keygen -o ci.key 2> /dev/null
ADA=$(age-keygen -y ada.key)            # derive the public recipient from the identity
CI=$(age-keygen -y ci.key)
echo "recipient: ${ADA:0:4}… (${#ADA} chars); identity file starts with: $(grep -o '^AGE-SECRET-KEY-1' ada.key)"

printf 'DB_PASSWORD=c0rrect-h0rse\n' > linkly.env
# encrypt for two recipients: a person and the CI system
age -r "$ADA" -r "$CI" -o linkly.env.age linkly.env
head -c 21 linkly.env.age; echo
echo "recipient stanzas in the header: $(grep -ac '^-> X25519' linkly.env.age)"

age -d -i ada.key linkly.env.age
age -d -i ci.key linkly.env.age
age-keygen -o mallory.key 2> /dev/null
age -d -i mallory.key linkly.env.age 2>&1 | sed 's/^age: //'
recipient: age1… (62 chars); identity file starts with: AGE-SECRET-KEY-1
age-encryption.org/v1
recipient stanzas in the header: 2
DB_PASSWORD=c0rrect-h0rse
DB_PASSWORD=c0rrect-h0rse
error: no identity matched any of the recipients
report unexpected or unhelpful errors at https://filippo.io/age/report

Each recipient can decrypt independently; someone else's identity gets a clear error. To revoke a recipient you re-encrypt without them, and rotate the secret itself, since they may have kept a copy.

Recipient files and armor

Teams keep recipients in a file in the repository, one per line, with comments:

bash · try it yourself
umask 077
age-keygen -o ada.key 2> /dev/null
age-keygen -o grace.key 2> /dev/null
cat > recipients.txt <<EOF
# team-links: ada
$(age-keygen -y ada.key)
# team-links: grace
$(age-keygen -y grace.key)
EOF
echo "recipients: $(grep -c '^age1' recipients.txt)"

echo 'stripe_key=sk_test_example' | age -R recipients.txt -a > stripe.age
head -1 stripe.age
age -d -i grace.key stripe.age
age -d -i ada.key stripe.age
recipients: 2
-----BEGIN AGE ENCRYPTED FILE-----
stripe_key=sk_test_example
stripe_key=sk_test_example
  • -R recipients.txt reads recipients from a file (comments allowed); -a produces PEM-like ASCII armor, convenient for pasting into a ticket or a chat.
  • SSH keys work too: an ssh-ed25519 or ssh-rsa public key is a valid recipient, and the private key an identity (age -R ~/.ssh/id_ed25519.pub …, age -d -i ~/.ssh/id_ed25519 …). Convenient for small teams that already know each other's SSH keys, but SSH keys get rotated and lost differently from encryption keys; for long-lived data prefer dedicated age keys. (The sandbox has no ssh-keygen, so this variant isn't run here.)
  • Passphrase-only encryption (age -p) needs an interactive terminal; for automation use keys.

Where age fits

  • Directly: encrypting a backup or a handover file for a known person.
  • Through SOPS: encrypting individual values inside YAML/JSON/ENV files in Git, with recipients listed in .sops.yaml (next lesson).
  • Plugins: age-plugin-yubikey and others keep identities on hardware tokens.

Protect identity files like any private key: 0600 permissions, never in the repository, stored in a password manager or a KMS-backed setup for CI (for example the age key as a CI secret, or better SOPS with a cloud KMS so CI needs no key file at all).

Test yourself

Which age key is safe to commit to a repository?

  1. AGE-SECRET-KEY-1…
  2. The age1… recipient (public key)
  3. Both
  4. Neither

A file is encrypted for three recipients. How do you remove one person's access?

  1. Delete their recipient line; the file updates itself
  2. Re-encrypt without their recipient and rotate the secret, since they may have a copy
  3. Change the file name
  4. Nothing can be done