13 个版本 (7 个重大更新)

0.10.0 2024年2月4日
0.9.2 2023年6月13日
0.9.1 2023年3月24日
0.9.0 2022年10月27日
0.0.19 2018年11月11日

#295 in 命令行工具

Download history 1862/week @ 2024-03-29 1342/week @ 2024-04-05 1093/week @ 2024-04-12 1216/week @ 2024-04-19 1716/week @ 2024-04-26 1262/week @ 2024-05-03 1671/week @ 2024-05-10 1327/week @ 2024-05-17 1490/week @ 2024-05-24 904/week @ 2024-05-31 2146/week @ 2024-06-07 1284/week @ 2024-06-14 280/week @ 2024-06-21 71/week @ 2024-06-28 240/week @ 2024-07-05 162/week @ 2024-07-12

每月 873 次下载

MIT/Apache

1.5MB
11K SLoC

Rust 9K SLoC // 0.0% comments FreeMarker 2K SLoC

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

rage: age 的 Rust 实现

rage 是一个简单、现代且安全的文件加密工具,使用 age 格式。它具有小而明确的密钥、无配置选项和 UNIX 风格的可组合性。

格式规范在 age-encryption.org/v1。age 由 @Benjojo12@FiloSottile 设计。

可互操作的参考 Go 实现可在 filippo.io/age 获得。

通过 age-plugin-yubikey 插件支持硬件 PIV 令牌,如 YubiKeys。

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

安装

环境 CLI 命令
Cargo (Rust 1.65+) cargoinstall rage
Homebrew (macOS 或 Linux) brewtap str4d.xyz/rage https://str4d.xyz/rage
brewinstall rage
Alpine Linux (edge) apk add rage
Arch Linux pacman -S rage-encryption
Debian Debian 软件包
NixOS 添加到配置: environment.systemPackages = [ pkgs.rage ];
或者运行 nix-env -i rage
openSUSE Tumbleweed zypper install rage-加密
Ubuntu 20.04+ Debian 软件包
FreeBSD pkg install rage-加密
Scoop (Windows) scoop bucket add main
scoop install main/rage

在 Windows、Linux 和 macOS 上,您可以使用 预构建的二进制文件

欢迎来自新打包者的帮助。请使用包名 rage;当使用全局命名空间的包系统中有无法避免的名称冲突时,才应使用回退包名 rage-encryption。不要重命名任何二进制文件;相反,使用您的包系统的冲突包机制来防止同时安装两个包。

用法

Usage: rage [--encrypt] (-r RECIPIENT | -R PATH)... [-i IDENTITY] [-a] [-o OUTPUT] [INPUT]
       rage [--encrypt] --passphrase [-a] [-o OUTPUT] [INPUT]
       rage --decrypt [-i IDENTITY] [-o OUTPUT] [INPUT]

Arguments:
  [INPUT]  Path to a file to read from.

Options:
  -h, --help                    Print this help message and exit.
  -V, --version                 Print version info and exit.
  -e, --encrypt                 Encrypt the input (the default).
  -d, --decrypt                 Decrypt the input.
  -p, --passphrase              Encrypt with a passphrase instead of recipients.
      --max-work-factor <WF>    Maximum work factor to allow for passphrase decryption.
  -a, --armor                   Encrypt to a PEM encoded format.
  -r, --recipient <RECIPIENT>   Encrypt to the specified RECIPIENT. May be repeated.
  -R, --recipients-file <PATH>  Encrypt to the recipients listed at PATH. May be repeated.
  -i, --identity <IDENTITY>     Use the identity file at IDENTITY. May be repeated.
  -j <PLUGIN-NAME>              Use age-plugin-PLUGIN-NAME in its default mode as an identity.
  -o, --output <OUTPUT>         Write the result to the file at path OUTPUT.

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, as generated by rage-keygen ("age1...").
- An SSH public key ("ssh-ed25519 AAAA...", "ssh-rsa AAAA...").

PATH is a path to a file containing age recipients, one per line
(ignoring "#" prefixed comments and empty lines). "-" may be used to
read recipients from standard input.

IDENTITY is a path to a file with age identities, one per line
(ignoring "#" prefixed comments and empty lines), or to an SSH key file.
Passphrase-encrypted age identity files can be used as identity files.
Multiple identities may be provided, and any unused ones will be ignored.
"-" may be used to read identities from standard input.

多个接收者

可以通过重复使用 -r/--recipient 来将文件加密给多个接收者。每个接收者都将能够解密文件。

$ rage -o example.png.age -r age1uvscypafkkxt6u2gkguxet62cenfmnpc0smzzlyun0lzszfatawq4kvf2u \
    -r age1ex4ty8ppg02555at009uwu5vlk5686k3f23e7mac9z093uvzfp8sxr5jum example.png

接收者文件

也可以使用 -R/--recipients-file 标志将多个接收者按行列出在一个或多个文件中。

$ cat recipients.txt
# Alice
age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
# Bob
age1lggyhqrw2nlhcxprm67z43rta597azn8gknawjehu9d9dl0jq3yqqvfafg
$ rage -R recipients.txt example.jpg > example.jpg.age

如果 -R(或 -)的参数是 -,则从标准输入读取文件。

密码短语

可以使用 -/--passphrase 使用密码短语加密文件。默认情况下,rage 将自动生成一个安全的密码短语。

$ rage -p -o example.png.age example.png
Type passphrase (leave empty to autogenerate a secure one): [hidden]
Using an autogenerated passphrase:
    kiwi-general-undo-bubble-dwarf-dizzy-fame-side-sunset-sibling
$ rage -d example.png.age >example.png
Type passphrase: [hidden]

如果 pinentry 二进制文件在 $PATH 中可用,它将用于提示用户输入密码短语。可以使用 PINENTRY_PROGRAM 环境变量来设置要使用的二进制文件名或路径。如果不可用 pinentry 二进制文件或 PINENTRY_PROGRAM 设置为空字符串,rage 将回退到 CLI。

密码短语保护的标识文件

如果传递给 -/--identity 的标识文件是一个密码短语加密的 age 文件,它将自动解密。

$ rage -p -o key.age <(rage-keygen)
Public key: age1pymw5hyr39qyuc950tget63aq8vfd52dclj8x7xhm08g6ad86dkserumnz
Type passphrase (leave empty to autogenerate a secure one): [hidden]
Using an autogenerated passphrase:
    flash-bean-celery-network-curious-flower-salt-amateur-fence-giant
$ rage -r age1pymw5hyr39qyuc950tget63aq8vfd52dclj8x7xhm08g6ad86dkserumnz secrets.txt > secrets.txt.age
$ rage -d -i key.age secrets.txt.age > secrets.txt
Type passphrase: [hidden]

对于大多数用例,密码短语保护的标识文件不是必需的,因为访问加密的标识文件意味着可以访问整个系统。然而,如果标识文件存储在远程位置,它们可能很有用。

SSH 密钥

作为一个便利功能,rage 还支持加密到 ssh-rsassh-ed25519 SSH 公钥,并使用相应的私钥文件进行解密。(不支持 ssh-agent。)

$ rage -R ~/.ssh/id_ed25519.pub example.png > example.png.age
$ rage -d -i ~/.ssh/id_ed25519 example.png.age > example.png

请注意,SSH 密钥支持使用更复杂的加密,并在加密文件中嵌入公钥标签,这使得可以跟踪加密到特定公钥的文件。

功能标志

当使用 Cargo 构建时,您可以使用 --no-default-features--features comma,separated,flags 来配置 rage,以启用或禁用以下功能标志

  • mount 启用 rage-mount 工具,该工具可以将 age 加密的 TAR 或 ZIP 归档作为只读挂载。目前它只能在 Unix 系统上使用,因为它依赖于 libfuse

  • ssh(默认启用)启用对现有 SSH 密钥文件的重用,用于 age 加密。

  • unstable 启用开发中的功能。此功能标志后面的任何内容都没有稳定性和互操作性保证。

Rust 库

希望将 rage 作为库使用的应用程序应使用 age crate,rage 是基于它构建的。

许可证

根据以下任一许可证授权

由您选择。

贡献

除非您明确声明,否则根据Apache-2.0许可证定义的任何有意提交以包含在作品中的贡献,应如上所述双重许可,不附加任何额外条款或条件。

依赖项

约15-29MB
~419K SLoC