FiloSottile/age

GitHub: FiloSottile/age

一款简洁现代的文件加密工具,主打小密钥、零配置和 UNIX 风格可组合性。

Stars: 21503 | Forks: 621

The age logo, a wireframe of St. Peters dome in Rome, with the text: age, file encryption

[![Go 参考](https://pkg.go.dev/badge/filippo.io/age.svg)](https://pkg.go.dev/filippo.io/age) [![man 手册](https://raw.githubusercontent.com/FiloSottile/age/main/)](https://filippo.io/age/age.1) [![C2SP 规范](https://img.shields.io/badge/%C2%A7%23-specification-blueviolet)](https://age-encryption.org/v1) 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](https://age-encryption.org/v1)。age 由 [@benjojo](https://github.com/benjojo) 和 [@FiloSottile](https://github.com/FiloSottile) 设计。 🦀 一个可互操作的 Rust 替代实现可在 [github.com/str4d/rage](https://github.com/str4d/rage) 找到。 🌍 [Typage](https://github.com/FiloSottile/typage) 是一个 TypeScript 实现。它可在浏览器、Node.js、Deno 和 Bun 中工作。 🔑 通过 [age-plugin-yubikey](https://github.com/str4d/age-plugin-yubikey) 插件支持硬件 PIV 令牌(如 YubiKeys)。 ✨ 欲了解更多插件、实现、工具和集成,请查看 [awesome age](https://github.com/FiloSottile/awesome-age) 列表。 💬 作者将其发音为 `[aɡe̞]` [带有硬 *g*](https://translate.google.com/?sl=it&text=aghe),就像 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 (启用 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` 获取机器可读的输出。
标签:Age, DevSecOps, DNS 反向解析, EVTX分析, EVTX分析, Go语言, ProjectDiscovery, Rust实现, TypeScript实现, UNIX风格, YAML, YubiKey支持, 上游代理, 云配置检测, 内存分配, 加密工具, 可组合性, 后量子密码学, 安全库, 数据保护, 文件加密, 日志审计, 程序破解, 网络安全, 隐私保护, 非对称加密