CLI reference
Overview
| Command | Description |
|---|---|
encrypt | Encrypt a file |
decrypt | Decrypt a .mdstn file |
keys | Create, list, alias, delete, export, publish and unpublish keys |
lookup | Look up a public key by email through CKD |
backup | Export keys and policies to a backup file |
restore | Import keys and policies from a backup file |
recover | Rebuild a key from its 24-word recovery phrase |
check-expiry | Record notifications for expired and expiring keys |
mcp | Start the MCP server for AI assistants |
version | Show version information |
completion | Generate a shell completion script |
Global flags
| Flag | Default | Description |
|---|---|---|
--db | ~/.mdstn/cipher.db | Key database path |
--config | ~/.mdstn/cipher.toml | Configuration file |
--json | false | Print exactly one JSON value on stdout; logs and progress go to stderr |
-v, --verbose | false | Verbose output |
Exit codes: 0 success, 1 usage or parse error, 2 tampered file, 3 not a recipient, 4
wrong file password, 5 directory binding conflict, 6 directory answer failed its integrity
check. See Format and security.
encrypt
mdstn-cipher encrypt <file> [flags]Without a method flag, encrypt asks for a file password.
| Flag | Description |
|---|---|
--password | Encrypt with this file password (no key needed) |
--password-file | Read the file password from a file, or - for stdin (one trailing newline is removed) |
--key-passphrase-file | Encrypt to your default key; read its passphrase from a file, or - for stdin. Creates the default key if you have none |
--for | Encrypt for one recipient, by email, through CKD |
--recipient | Encrypt for several recipients, by email or key ID (repeatable or comma-separated); any one can decrypt |
--recipient-key | Encrypt for a raw X25519 public key: base64 of 32 bytes, or a file that holds it (repeatable) |
-o, --output | Output path. Replaces an existing file, but never the input |
--force | Let the default output path <file>.mdstn replace an existing file |
mdstn-cipher encrypt secret.pdf
mdstn-cipher encrypt secret.pdf --password-file pw.txt
mdstn-cipher encrypt secret.pdf --for alice@example.com
mdstn-cipher encrypt secret.pdf --recipient alice@example.com --recipient bob@example.com
mdstn-cipher encrypt secret.pdf --recipient-key alice.pub -o secret.mdstndecrypt
mdstn-cipher decrypt <file> [flags]The method is read from the file header. Without --output, the plaintext goes to the input path
without .mdstn (else the input path plus .decrypted), and an existing file is never replaced.
The sender’s file name in the header is shown, never used as a path.
| Flag | Description |
|---|---|
--password | File password for a password-encrypted file |
--password-file | Read the file password from a file, or - for stdin |
--key-passphrase-file | Read your key passphrase (or recovery phrase) from a file, or - for stdin |
-o, --output | Output path. Replaces an existing file, but never the input |
--force | Let the default output path replace an existing file |
mdstn-cipher decrypt secret.pdf.mdstn
mdstn-cipher decrypt secret.pdf.mdstn --output decrypted.pdf
mdstn-cipher decrypt secret.pdf.mdstn --key-passphrase-file - < key-pass.txtkeys
| Subcommand | Usage | Description |
|---|---|---|
create | keys create [flags] | Create a key and show its 24-word recovery phrase |
list | keys list | List keys: ID, type, alias, created, usage, default, expiry |
alias | keys alias <key> <alias> | Set a key’s alias |
delete | keys delete <key> | Delete a key |
export | keys export <key> -o <file> [--format pem|raw] | Export the wrapped private key (file mode 0600) |
publish | keys publish --email <email> [flags] | Publish your X25519 public key to the directory |
unpublish | keys unpublish --email <email> [flags] | Remove your key from the directory |
status | keys status [fingerprint] | Check whether a key is published |
<key> is a key ID or a full fingerprint.
keys create flags
| Flag | Description |
|---|---|
--alias | Key alias |
--type | x25519 (default) or aes256 |
--expires-in | Lifetime, for example 30d, 4w, 720h |
--expires-at | Expiry as an RFC 3339 timestamp |
--key-passphrase | Key passphrase (wins over --key-passphrase-file and MDSTN_KEY_PASSPHRASE) |
--key-passphrase-file | Read the key passphrase from a file, or - for stdin |
--yes | Skip the 3-word recovery phrase confirmation (required without a terminal) |
Directory flags
For publish, unpublish and status.
| Flag | Description |
|---|---|
--email | Your email address (publish and unpublish, required) |
--kd-token | Directory token; wins over KD_TOKEN. Get one at keys.mdstn.dev |
--server-url | Directory URL; wins over CIPHER_SERVER_URL. Default https://keys.mdstn.dev |
--fingerprint | publish: the current binding’s fingerprint, for rotation. status: the fingerprint to check |
keys status checks, in order, --fingerprint, the positional fingerprint, then your default key.
lookup
mdstn-cipher lookup <email> [flags]| Flag | Description |
|---|---|
--save | Save the result to the local cache |
--refresh | Run the discovery chain again, ignoring the cache; show any change without applying it |
--yes | With --refresh: accept a changed key without asking |
--json | JSON output |
See Key discovery (CKD).
backup and restore
mdstn-cipher backup [-o <file>]
mdstn-cipher restore <backup-file> [--force]backup writes to ~/.mdstn/backups/cipher-backup-YYYYMMDD-HHMMSS.json by default and never
replaces a file. restore --force replaces keys and policies that already exist.
recover
mdstn-cipher recover from-mnemonicAsks for a 24-word recovery phrase and a new key passphrase, then rebuilds the key.
check-expiry
mdstn-cipher check-expiryRecords one notification per key that has expired or expires within 1 or 7 days. Suitable for cron.
mcp
mdstn-cipher mcpStarts the MCP server on stdio. See MCP server.
version and completion
mdstn-cipher version [--json]
mdstn-cipher completion <bash|zsh|fish|powershell>Environment variables
| Variable | Used by | Effect |
|---|---|---|
MDSTN_KEY_PASSPHRASE | keys create | Key passphrase, when no flag gives one |
KD_TOKEN | keys publish, unpublish, status | Directory token |
CIPHER_SERVER_URL | keys publish, unpublish, status | Directory URL |
CIPHER_CKD_URL | lookup, encrypt --for | Hosted directory for lookups (staging or tests) |