
一个简单、现代且安全的加密工具(及 Go 库),具有简短明确的密钥、无配置选项,以及 UNIX 风格的可组合性。
age 是一款简单、现代且安全的文件加密工具、格式和 Go 库。
它具备小巧明确的密钥、后量子支持、无配置选项以及 UNIX 风格的可组合性。
$ age-keygen -o key.txt
Public key: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
$ tar cvz ~/data | age -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age
$ age --decrypt -i key.txt data.tar.gz.age > data.tar.gz
📜 格式规范位于 age-encryption.org/v1。age 由 @benjojo 和 @FiloSottile 设计。
🦀 另一个可互操作的 Rust 实现位于 github.com/str4d/rage。
🌍 Typage 是一个 TypeScript 实现。它可在浏览器、Node.js、Deno 和 Bun 中运行。
🔑 通过 age-plugin-yubikey 插件支持 YubiKey 等硬件 PIV 令牌。
✨ 更多插件、实现、工具和集成,请查看 awesome age 列表。
💬 作者将其发音为 [aɡe̞],带有硬音 g,类似 GIF,并且始终以小写拼写。
在 Windows、Linux、macOS 和 FreeBSD 上,您可以使用预编译二进制文件。
如果您下载了预编译二进制文件,可以验证其 Sigsum 证明。
如果您的系统具有受支持的 Go 版本,则可以从源代码构建。
go install filippo.io/age/cmd/...@latest
非常欢迎新的打包者提供帮助。
完整文档请阅读 age(1) 手册页。
Usage:
age [--encrypt] (-r RECIPIENT | -R PATH)... [--armor] [-o OUTPUT] [INPUT]
age [--encrypt] --passphrase [--armor] [-o OUTPUT] [INPUT]
age --decrypt [-i PATH]... [-o OUTPUT] [INPUT]
Options:
-e, --encrypt Encrypt the input to the output. Default if omitted.
-d, --decrypt Decrypt the input to the output.
-o, --output OUTPUT Write the result to the file at path OUTPUT.
-a, --armor Encrypt to a PEM encoded format.
-p, --passphrase Encrypt with a passphrase.
-r, --recipient RECIPIENT Encrypt to the specified RECIPIENT. Can be repeated.
-R, --recipients-file PATH Encrypt to recipients listed at PATH. Can be repeated.
-i, --identity PATH Use the identity file at PATH. Can be repeated.
--version Print the version.
INPUT defaults to standard input, and OUTPUT defaults to standard output.
If OUTPUT exists, it will be overwritten.
RECIPIENT can be an age public key generated by age-keygen ("age1...")
or an SSH public key ("ssh-ed25519 AAAA...", "ssh-rsa AAAA...").
Recipient files contain one or more recipients, one per line. Empty lines
and lines starting with "#" are ignored as comments. "-" may be used to
read recipients from standard input.
Identity files contain one or more secret keys ("AGE-SECRET-KEY-1..."),
one per line, or an SSH key. Empty lines and lines starting with "#" are
ignored as comments. Passphrase encrypted age files can be used as
identity files. Multiple key files can be provided, and any unused ones
will be ignored. "-" may be used to read identities from standard input.
When --encrypt is specified explicitly, -i can also be used to encrypt to an
identity file symmetrically, instead or in addition to normal recipients.
可以通过重复 -r/--recipient 将文件加密给多个接收者。每个接收者都能解密该文件。
$ age -o example.jpg.age -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p \
-r age1lggyhqrw2nlhcxprm67z43rta597azn8gknawjehu9d9dl0jq3yqqvfafg example.jpg
多个接收者也可以逐行列在一个或多个通过 -R/--recipients-file 标志传递的文件中。
$ cat recipients.txt
# Alice
age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
# Bob
age1lggyhqrw2nlhcxprm67z43rta597azn8gknawjehu9d9dl0jq3yqqvfafg
$ age -R recipients.txt example.jpg > example.jpg.age
如果 -R(或 -i)的参数是 -,则从标准输入读取文件。
要生成混合后量子密钥(可抵御未来量子计算机攻击),请在 age-keygen 中使用 -pq 标志。这可能在将来成为默认选项。
后量子身份以 AGE-SECRET-KEY-PQ-1... 开头,接收者以 age1pq1... 开头。遗憾的是,接收者长度约为 2000 个字符。
$ age-keygen -pq -o key.txt
$ age-keygen -y key.txt > recipient.txt
$ age -R recipient.txt example.jpg > example.jpg.age
$ age -d -i key.txt example.jpg.age > example.jpg
后量子密钥支持已内置于 age v1.3.0 及更高版本。或者,可以安装 age-plugin-pq 二进制文件并将其放入 $PATH,以便为任何支持插件的 age 版本和实现添加支持。接收者开箱即用,而身份则需要使用 age-plugin-pq -identity 转换为插件身份。
可以使用 -p/--passphrase 通过口令加密文件。默认情况下,age 会自动生成一个安全的口令。受口令保护的文件在解密时会自动检测。
$ age -p secrets.txt > secrets.txt.age
Enter passphrase (leave empty to autogenerate a secure one):
Using the autogenerated passphrase "release-response-step-brand-wrap-ankle-pair-unusual-sword-train".
$ age -d secrets.txt.age > secrets.txt
Enter passphrase:
如果传递给 -i 的身份文件是受口令加密的 age 文件,它将被自动解密。
$ age-keygen | age -p > key.age
Public key: age1yhm4gctwfmrpz87tdslm550wrx6m79y9f2hdzt0lndjnehwj0ukqrjpyx5
Enter passphrase (leave empty to autogenerate a secure one):
Using the autogenerated passphrase "hip-roast-boring-snake-mention-east-wasp-honey-input-actress".
$ age -r age1yhm4gctwfmrpz87tdslm550wrx6m79y9f2hdzt0lndjnehwj0ukqrjpyx5 secrets.txt > secrets.txt.age
$ age -d -i key.age secrets.txt.age > secrets.txt
Enter passphrase for identity file "key.age":
对于大多数使用场景,受口令保护的身份文件并非必需,因为能够访问加密身份文件通常意味着能够访问整个系统。但是,如果身份文件存储在远程位置,它们可能会很有用。
作为一项便捷功能,age 还支持加密到 ssh-rsa 和 ssh-ed25519 SSH 公钥,并使用相应的私钥文件进行解密。(不支持 ssh-agent。)
$ age -R ~/.ssh/id_ed25519.pub example.jpg > example.jpg.age
$ age -d -i ~/.ssh/id_ed25519 example.jpg.age > example.jpg
请注意,SSH 密钥支持采用了更复杂的密码学,并在加密文件中嵌入了公钥标签,从而可以追踪加密到特定公钥的文件。
结合 SSH 密钥支持和 -R,您可以轻松地将文件加密到 GitHub 个人资料中列出的 SSH 密钥。
$ curl https://github.com/benjojo.keys | age -R - example.jpg > example.jpg.age
请记住,人们可能不会长期保护 SSH 密钥,因为当它们仅用于身份验证时可以撤销,而且保存在 YubiKey 上的 SSH 密钥无法用于解密文件。
age-inspect 命令可以在不解密的情况下显示加密文件的元数据,包括接收者类型、是否使用后量子加密以及负载大小。
$ age-inspect secrets.age
secrets.age is an age file, version "age-encryption.org/v1".
This file is encrypted to the following recipient types:
- "mlkem768x25519"
This file uses post-quantum encryption.
Size breakdown (assuming it decrypts successfully):
Header 1627 bytes
Encryption overhead 32 bytes
Payload 42 bytes
-------------------
Total 1701 bytes
Tip: for machine-readable output, use --json.
| Homebrew(macOS 或 Linux) |
brew install age
|
| MacPorts |
port install age
|
| Windows |
winget install --id FiloSottile.age
|
| Alpine Linux v3.15+ |
apk add age
|
| Arch Linux |
pacman -S age
|
| Debian 12+(Bookworm) |
apt install age
|
| Debian 11(Bullseye) |
apt install age/bullseye-backports
(启用 backports 以获取 age v1.0.0+)
|
| Fedora 33+ |
dnf install age
|
| Gentoo Linux |
emerge app-crypt/age
|
| Guix System |
guix package -i age
|
| NixOS / Nix |
nix-env -i age
|
| openSUSE Tumbleweed |
zypper install age
|
| Ubuntu 22.04+ |
apt install age
|
| Void Linux |
xbps-install age
|
| FreeBSD |
pkg install age(security/age)
|
| OpenBSD 6.7+ |
pkg_add age(security/age)
|
| Chocolatey(Windows) |
choco install age.portable
|
| Scoop(Windows) |
scoop bucket add extras && scoop install age
|