Skip to content

rypt-cli

rypt-cli installs rypt, a command that encrypts and decrypts files of any size in envelope mode. rypt encrypt has rypt wrap a new 32-byte data key, encrypts the file on your machine under it, and writes a .rypt file that holds the wrapped data key in its header. rypt decrypt sends that wrapped data key to unwrap and decrypts the file on your machine. The file does not reach rypt, but its data key does, so this is not zero-knowledge. Direct or envelope explains the mode.

This page describes v0.3.0.

On macOS:

brew install --cask x6c-co/tap/rypt

The cask installs the release binary for your Mac as rypt. The macOS binaries are signed with a Developer ID certificate and notarized by Apple.

Each release has a binary for each platform and a SHA256SUMS file. On Linux on amd64, download both and check the binary against the sums:

curl -fsSLO https://github.com/x6c-co/rypt-cli/releases/download/v0.3.0/rypt-linux-amd64
curl -fsSLO https://github.com/x6c-co/rypt-cli/releases/download/v0.3.0/SHA256SUMS
sha256sum -c --ignore-missing SHA256SUMS
rypt-linux-amd64: OK

The checksum shows only that the file matches SHA256SUMS, which is published beside it. The file's build provenance attestation shows that the release workflow in x6c-co/rypt-cli built it from the tagged commit. Check it with the GitHub CLI, which exits 0 when the file passes:

gh attestation verify rypt-linux-amd64 --repo x6c-co/rypt-cli --signer-workflow x6c-co/rypt-cli/.github/workflows/release.yml

Then put it on your PATH:

sudo install -m 0755 rypt-linux-amd64 /usr/local/bin/rypt

On another platform, use rypt-linux-arm64, rypt-darwin-arm64 or rypt-darwin-amd64 in these commands. On macOS, check the sums with shasum -a 256 -c --ignore-missing SHA256SUMS. On Windows, download rypt-windows-amd64.exe or rypt-windows-arm64.exe and rename it to rypt.exe.

go install github.com/x6c-co/rypt-cli/cmd/rypt@v0.3.0

This needs Go 1.27.2 or later; with GOTOOLCHAIN=auto, go downloads it first. The binary goes to $(go env GOPATH)/bin, or to GOBIN if that is set, and that directory has to be on your PATH.

rypt version
rypt v0.3.0

If rypt version does not print rypt v0.3.0 or later, an older rypt-cli or another program named rypt comes first on your PATH: type -a rypt lists each one, in the order your shell finds them. rypt help prints the usage, the flags and the exit codes.

rypt encrypt calls wrap and rypt decrypt calls unwrap, so the API token needs those two actions. rypt-cli never lists keys, so it needs no read. The API token from the quickstart, like the one the dashboard's Overview issues, has only encrypt and decrypt, and gets 403 action_not_allowed from rypt-cli. Issue one for it with the key's container chosen in the Container menu (see the pieces):

  1. Open API tokens and press Issue API token.
  2. Enter a Name. Under What it may do, in the Use keys group, tick wrap and unwrap.
  3. Press Issue API token.
  4. Press Copy token and store the API token. Tick I have stored this token. and press Done.
  5. To hold it to one key, press Restrict on its row, choose Only these keys under Encryption keys it may use, tick the key, and press Save.

A machine that only decrypts needs only unwrap, but unwrap also opens what encrypt makes: see what each action covers.

rypt-cli reads the API token from RYPT_TOKEN. There is no flag for it, so the API token is never on rypt's command line, which ps shows to every user of the machine. Put the new API token in RYPT_TOKEN, in place of the quickstart's, exactly as copied: rypt-cli refuses an API token with a space or any other character that is not printable ASCII. rypt encrypt takes its key from RYPT_KEY_ID. After the quickstart the key id is in KEY_ID; otherwise write the key's Key id in place of $KEY_ID:

export RYPT_TOKEN='ry_K3pQ7xTa_...'
export RYPT_KEY_ID="$KEY_ID"

rypt decrypt reads the key id from the file, so it needs only RYPT_TOKEN.

Make a file to try it on: printf 'hello world\n' > notes.txt.

rypt encrypt notes.txt

This writes notes.txt.rypt and prints nothing. It costs 1 operation whatever the size of the file, which is encrypted in 64 KiB chunks under the one data key. Only you can read the output:

ls -l notes.txt.rypt
-rw------- 1 you you 152 Nov  5 16:35 notes.txt.rypt

rypt decrypt notes.txt.rypt would write notes.txt, but rypt-cli never replaces a file unless you give --force, and notes.txt is still there:

rypt decrypt notes.txt.rypt
rypt: refusing to replace the existing file notes.txt; use --force to replace it

A refusal like this comes before any call to rypt, so it costs nothing. Name the output with -o instead:

rypt decrypt -o notes.copy.txt notes.txt.rypt && cmp notes.txt notes.copy.txt && echo same
same

-o - writes the plaintext to standard output:

rypt decrypt -o - notes.txt.rypt
hello world

Each decrypt costs 1 operation. rypt-cli writes to a temporary file beside the output and moves it into place when it is done; rypt decrypt does so only once the whole file has authenticated, so a damaged file leaves no output behind. rypt-cli never writes over its own input.

With no file, or with -, rypt-cli reads standard input and writes standard output. That is how to encrypt a directory: archive it with tar. Here photos/ is any directory of yours in the current directory. Make an empty restore/ beside it with mkdir -p restore. Set pipefail, so that a failure anywhere in a pipe fails the whole command:

set -o pipefail; tar -czf - photos/ | rypt encrypt --label photos-2026 > photos.tgz.rypt; echo "exit $?"
exit 0

A shell redirect such as > photos.tgz.rypt replaces an existing file before rypt-cli runs, so the --force check does not apply to it.

cd restore && rypt decrypt < ../photos.tgz.rypt | tar -xzf - && diff -r ../photos photos && echo same
same

That command leaves you in restore/. Go back up to the directory that holds notes.txt.rypt for the rest of this page.

rypt encrypt refuses to write ciphertext to a terminal. rypt decrypt to standard output writes each chunk as soon as it authenticates, so a damaged or truncated file can write part of its plaintext before rypt-cli exits with code 4. Discard the output of any run that does not exit 0; with pipefail, a pipe that includes it fails too.

--label binds the wrapped data key to a context, such as photos-2026 above. A label is at most 1,024 bytes of UTF-8. rypt-cli sends it as the aad of wrap and unwrap, and stores it in the clear in the file's header, so it is not a secret. rypt decrypt reads it from the header, and giving it --label is a usage error. No rypt command prints a file's label, so keep a note of the labels you use. See additional authenticated data.

Check a file without keeping the plaintext

Section titled "Check a file without keeping the plaintext"
rypt decrypt -o - notes.txt.rypt > /dev/null && echo intact
intact

This decrypts the whole file and throws the plaintext away, so it costs 1 operation, as any decrypt does. -o /dev/null is refused, because the output has to be a regular file. A changed file exits 4 with integrity check failed: see errors.

Flag With What it does
-k, --key-id UUID encrypt The key that wraps the data key, by its key id; a key name is refused. The default is RYPT_KEY_ID. decrypt takes the key id from the file and ignores this flag.
-o, --output PATH both The output path; - is standard output. Without it, encrypt writes FILE.rypt, and decrypt writes FILE for FILE.rypt and needs -o for any other name.
-f, --force both Replace an existing output file.
--cipher NAME encrypt aes-256-gcm, the default, or xchacha20-poly1305.
--label TEXT encrypt See labels.
-h, --help both Print the usage.

Each successful call to rypt is one operation, and a call rypt refuses is not counted.

Command Operations
rypt encrypt, whatever the size of the file 1 wrap
rypt decrypt, including the check with -o - > /dev/null 1 unwrap
rypt decrypt of a changed or truncated file 1 unwrap, which succeeds before a chunk fails
rypt decrypt of a missing file, or of one whose header rypt-cli cannot read 0
rypt version, rypt help, a usage error or a refused overwrite 0
Encrypting a file again after a rotation 2: 1 unwrap and 1 wrap

After a dropped connection or a 502, 503 or 504, rypt-cli retries a call at most twice, and a retry may count too.

Situation rypt encrypt rypt decrypt
rypt cannot be reached Fails, exit 1 Fails, exit 1: there is no offline way to decrypt
RYPT_TOKEN is not set Fails, exit 2, before any call to rypt Fails, exit 2, before any call to rypt
The API token is wrong or revoked 401 unauthorized 401 unauthorized
The machine is outside the API token's firewall 403 ip_not_allowed 403 ip_not_allowed
The API token has unwrap only 403 action_not_allowed Works
A Free key is at its monthly cap 429 ops_cap_reached Works
A paid key's billing is not in good standing 402 billing_required (billing refusals) Works
The key is pending deletion 409 key_pending_deletion 409 key_pending_deletion
The key is destroyed 404 not_found 404 not_found, and the files are lost
The file's key version is destroyed Works 400 invalid_ciphertext, and the file is lost

At a Free key's monthly cap, rypt refuses to encrypt until 00:00 UTC on the 1st, and goes on decrypting.

A deleted key refuses every operation for 7 days, during which Restore on its page in the dashboard brings it back. After those 7 days, or at once with Delete now, the key is destroyed, and whatever was encrypted only to it can never be decrypted again. See one Free key per tenant and errors.

A .rypt file can be read only through rypt. To keep a way to read files without rypt, encrypt them with age-plugin-rypt to both a rypt key and an offline recovery key.

On a Free key every rotation retires the version before it; a retired version keeps decrypting for 7 days and is then destroyed (Free keys). A paid key keeps every version until you retire one (versions per tier).

This loop encrypts again every .rypt file in the current directory that has no label, to the key in RYPT_KEY_ID:

set -o pipefail
for f in *.rypt; do
  if [ "$(od -An -tu1 -j26 -N2 "$f" | tr -d ' \n')" != 00 ]; then
    echo "skipped, has a label: $f" >&2
    continue
  fi
  if rypt decrypt -o - "$f" | rypt encrypt -o "$f.new"; then
    mv "$f.new" "$f"
  else
    rm -f "$f.new"
    echo "not moved: $f" >&2
  fi
done
skipped, has a label: photos.tgz.rypt

Each file is encrypted into FILE.rypt.new, which replaces it only when both halves succeed. pipefail makes that check work: without it, a failed decrypt would hand rypt encrypt an empty input, and the loop would replace the file with an encrypted empty file. With it, a failed decrypt leaves the file as it was, though the empty encrypt still runs and costs 1 wrap.

The loop skips each file that has a label, which it would otherwise drop: the od test reads the label's length from the header, and 00 means there is none. Encrypt each skipped file again by hand the way the loop does: pipe rypt decrypt -o - into rypt encrypt with the same --label and -o FILE.rypt.new, and once both exit 0, move FILE.rypt.new over FILE.rypt. No rypt command prints a label, so this needs your note of it.

An error from rypt names the call, then the code, the HTTP status, rypt's message and the request id. Encrypting to a key id that names no key:

rypt encrypt -k 00000000-0000-0000-0000-000000000000 -o z.rypt notes.txt
rypt: wrap: rypt API error not_found (HTTP 404): not found (request_id fd184a43-9639-4e8e-b7bc-2ba7c7104c4e)

A usage error other than a refusal is followed by a second line, Run 'rypt help' for usage. Each message names the file you gave rypt-cli; plain, missing.rypt and bad.rypt below stand for yours.

Message Cause
rypt: RYPT_TOKEN is not set Set RYPT_TOKEN to your API token.
rypt: RYPT_TOKEN contains a character that is not printable ASCII The API token was pasted with a space, a line break or another character around or in it. Copy it again, exactly.
rypt: no key ID: use --key-id or set RYPT_KEY_ID rypt encrypt needs a key. Set RYPT_KEY_ID or pass -k.
rypt: the key ID is not a UUID of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -k or RYPT_KEY_ID holds something other than a key id, such as a key's name. Use the key's Key id.
rypt: refusing to replace the existing file notes.txt; use --force to replace it The output file exists. Name another with -o, or replace it with --force.
rypt: refusing to write ciphertext to a terminal; use -o or redirect stdout rypt encrypt had no output but the terminal. Give -o, or redirect standard output to a file.
rypt: plain does not end in .rypt; use -o to name the output rypt decrypt names its output by dropping .rypt. Name it with -o.
rypt: photos is a directory; archive it first, for example with tar rypt-cli encrypts one file at a time. Archive the directory, as in standard input and output.
rypt: the output /dev/null is not a regular file; use -o - and redirect stdout to it Use -o - > /dev/null, as in the check.
rypt: --label applies to encrypt only; decrypt reads the label from the file header Leave --label off rypt decrypt.
rypt: unknown cipher "chacha": use aes-256-gcm or xchacha20-poly1305 Give one of those two names exactly.
rypt: open missing.rypt: no such file or directory The input file does not exist. It exits 3. Check the name, and run it from the directory that holds the file.
rypt: "bad.rypt": integrity check failed: chunk 0 failed authentication The file was changed or cut short after it was encrypted. It exits 4. Decrypt another copy of it.
rypt: wrap: cannot reach the rypt API after 3 attempts rypt-cli could not connect to rypt; the rest of the line names the network error. A certificate error, or a server that does not speak TLS, is not retried, so that line reads after 1 attempt. Check the connection and run it again. From decrypt, the line starts rypt: unwrap:.
rypt API error unauthorized (HTTP 401): missing or invalid credentials RYPT_TOKEN is not the whole API token, or the API token was revoked. Copy the API token into RYPT_TOKEN again, or issue another as in the API token it needs.
rypt API error action_not_allowed (HTTP 403): this api token may not wrap with this key The API token lacks wrap, or, from decrypt, unwrap. Add it with Restrict on the API tokens page, or issue one as in the API token it needs.
rypt API error key_not_allowed (HTTP 403): this api token is restricted to other keys The key is not on the API token's key list. Add it with Restrict, under Encryption keys it may use.
rypt API error ip_not_allowed (HTTP 403) The machine is outside the API token's firewall, and the message names the address rypt saw. Run it from a network the firewall allows, or add that address to the firewall: see firewalls.
rypt API error not_found (HTTP 404): not found The key id names no key the API token can reach: it is wrong, the key is in another container, or the key was destroyed. From encrypt, check -k or RYPT_KEY_ID against the key's Key id, and issue the API token in the key's container. A destroyed key cannot be brought back.
rypt API error key_pending_deletion (HTTP 409) The key was deleted, and the message says when it will be destroyed. Press Restore on its page in the dashboard.
rypt API error billing_required (HTTP 402) Only from encrypt: the key is a paid key and the tenant's billing is not in good standing. See billing refusals.
rypt API error ops_cap_reached (HTTP 429) Only from encrypt: the Free key is at its monthly cap, and the message gives the cap and when it resets. Encrypt again after that time; rypt decrypt goes on working.
rypt API error invalid_ciphertext (HTTP 400) rypt cannot open the wrapped data key in the header: the header was changed (ciphertext or aad invalid), or the key version the file was made under was destroyed (ciphertext refers to a key version that is not enabled). If the header was changed, decrypt another copy of the file. A file made under a destroyed version cannot be decrypted.

Errors lists every code the API returns.

Code Meaning
0 Success.
1 rypt refused the request, or could not be reached.
2 A usage error, including a refused overwrite, or rypt run with no command.
3 A local I/O error, such as a missing input file.
4 An integrity failure: a bad header, a chunk that fails authentication, or a truncated file.
130 Interrupted by SIGINT, SIGTERM or SIGHUP. rypt removes its temporary files.