Tools · Cryptography and passwords in practice · 07 / 20
Encrypting files with age: a simple modern alternative to GPG
Use age to generate keys, encrypt files for one or more recipients, use SSH keys as recipients, and understand when age is a better fit than GPG.
What age is
age is a small, modern file encryption tool and format designed by Filippo Valsorda. It uses X25519 for key agreement, ChaCha20-Poly1305 for authenticated encryption, and has no configuration options to get wrong. It only encrypts; it does not sign. That focus makes it easy to use correctly for backups, secrets in repositories (with tools like SOPS), and sending files.
Using it
age-keygen creates an identity file containing a private key and prints the public recipient string starting with age1. Encrypt with -r for each recipient or -R for a file of recipients. Passphrase mode with -p uses scrypt. age can also encrypt to existing SSH public keys.
age-keygen -o key.txt # prints: Public key: age1... age -r age1examplerecipient... -o backup.tar.gz.age backup.tar.gz age -d -i key.txt -o backup.tar.gz backup.tar.gz.age age -R recipients.txt -o shared.age notes.md age -p -o secret.age secret.txt age -R ~/.ssh/id_ed25519.pub -o for-me.age file.txt
Lab: tamper detection
Encrypt a test file for your own age key, flip one byte in the ciphertext with printf and dd, and try to decrypt. age refuses with an authentication error instead of producing corrupted output, unlike unauthenticated modes. Then add a second recipient and confirm either key can decrypt.
printf 'X' | dd of=backup.tar.gz.age bs=1 seek=300 count=1 conv=notrunc age -d -i key.txt -o out.tar.gz backup.tar.gz.age # expect an error
age or GPG?
Use age when you need straightforward encryption to known recipients. Use GPG when you need signatures, existing OpenPGP ecosystems such as email or package signing, or smart card support already built around it. For signing files with a simple tool, minisign or ssh-keygen -Y sign are lightweight alternatives.
Diagram
age versus GPG
Pick the tool for the job.
Does. Encryption, signing, key management, web of trust
Complexity. Many options and legacy algorithms
Good for. Release signing, OpenPGP email
Does. Encryption only
Complexity. Minimal, no options
Good for. Backups, secrets, sending files to known recipients
Check yourself
1. What happens when you decrypt an age file whose ciphertext was modified?
2. Can age sign files?
3. Which option encrypts to recipients listed in a file?