mcpField
A
age

age

官方Agent-ready
github.com开发者工具24.1kage9 周前更新
代码仓库访问官网

关于 age

age 是一个命令行加密工具,采用简单的密钥格式和现代加密标准。支持生成密钥对、加密和解密文件,集成友好的命令行界面使其适合自动化脚本和 CI 工作流。

主要功能

  1. 01使用 age-keygen 生成加密密钥对并保存到文件
  2. 02通过 -r 标志指定接收者公钥来加密文件
  3. 03输出加密结果到指定文件(-o 选项)

适用场景

  1. 01在 CI/CD 管道中自动加密敏感配置文件和部署秘钥
  2. 02编码 Agent 保护工作中的临时文件和中间数据
  3. 03开发人员安全交换加密文件而无需复杂的密钥管理基础设施

安装

选择你的系统或包管理器,复制命令到终端运行。

$
brew install age

安装完成后运行age --version确认安装成功。

命令示例

常用命令按使用顺序排列。

01
age-keygen -o key.txt
02
age -r RECIPIENT -o file.age file.txt

详细介绍

age 标志:罗马圣彼得大教堂穹顶的线框图,以及文字:age,文件加密

Go Reference Dependencies man page C2SP specification

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 插件支持 YubiKeys 等硬件 PIV 令牌。

✨ 更多插件、实现、工具和集成,请参阅 awesome age 列表。

💬 作者将其读作 [aɡe̞],其中 g 发硬音,就像 GIF 一样,并且始终使用小写拼写。

安装

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 (安装 age v1.0.0+ 需启用 backports)
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 上,你可以使用预编译的二进制文件。

如果你下载了预编译的二进制文件,可以验证其 Sigsum 证明。

如果你的系统安装了受支持版本的 Go,可以从源代码构建。

go install filippo.io/age/cmd/...@latest

非常欢迎新的软件包维护者提供帮助。

用法

完整文档请参阅 age(1) man 手册页。

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":

对于大多数用例,受密码短语保护的身份文件并非必要,因为能访问加密身份文件就意味着能访问整个系统。不过,如果身份文件存储在远程位置,它们可能会很有用。

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 密钥,因为这些密钥仅用于身份验证时可以撤销;此外,存储在 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.

评论

支持 Markdown