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
在 Windows、Linux、macOS 和 FreeBSD 上,你可以使用预编译的二进制文件。
```
https://dl.filippo.io/age/latest?for=linux/amd64
https://dl.filippo.io/age/v1.3.1?for=darwin/arm64
...
```
如果你下载了预编译的二进制文件,你可以检查它们的 [Sigsum 证明](./SIGSUM.md)。
如果你的系统拥有 [受支持的 Go 版本](https://go.dev/dl/),你可以从源代码构建。
```
go install filippo.io/age/cmd/...@latest
```
非常欢迎新打包者的帮助。
## 使用
完整文档请阅读 [age(1) man 手册](https://filippo.io/age/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.
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":
```
在大多数情况下,受密码短语保护的身份文件并不是必需的,因为访问加密的身份文件意味着可以访问整个系统。但是,如果身份文件存储在远程位置,它们可能会很有用。
### SSH 密钥
作为一个便利功能,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 密钥支持采用了更复杂的加密技术,并在加密文件中嵌入了公钥标签,这使得跟踪加密到特定公钥的文件成为可能。
#### 加密给 GitHub 用户
结合 SSH 寺支持 和 `-R`,你可以轻松地加密文件给 GitHub 配置文件中列出的 SSH 密钥。
```
$ curl https://github.com/benjojo.keys | age -R - example.jpg > example.jpg.age
```
请记住,人们可能不会长期保护 SSH 密钥,因为它们仅用于认证时是可撤销的,而且存储在 YubiKeys 上的 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
```
对于脚本编写,使用 `--json` 获取机器可读的输出。