Skip to content

CLI reference

GitHub →

Overview

CommandDescription
encryptEncrypt a file
decryptDecrypt a .mdstn file
keysCreate, list, alias, delete, export, publish and unpublish keys
lookupLook up a public key by email through CKD
backupExport keys and policies to a backup file
restoreImport keys and policies from a backup file
recoverRebuild a key from its 24-word recovery phrase
check-expiryRecord notifications for expired and expiring keys
mcpStart the MCP server for AI assistants
versionShow version information
completionGenerate a shell completion script

Global flags

FlagDefaultDescription
--db~/.mdstn/cipher.dbKey database path
--config~/.mdstn/cipher.tomlConfiguration file
--jsonfalsePrint exactly one JSON value on stdout; logs and progress go to stderr
-v, --verbosefalseVerbose 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.

FlagDescription
--passwordEncrypt with this file password (no key needed)
--password-fileRead the file password from a file, or - for stdin (one trailing newline is removed)
--key-passphrase-fileEncrypt to your default key; read its passphrase from a file, or - for stdin. Creates the default key if you have none
--forEncrypt for one recipient, by email, through CKD
--recipientEncrypt for several recipients, by email or key ID (repeatable or comma-separated); any one can decrypt
--recipient-keyEncrypt for a raw X25519 public key: base64 of 32 bytes, or a file that holds it (repeatable)
-o, --outputOutput path. Replaces an existing file, but never the input
--forceLet 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.mdstn

decrypt

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.

FlagDescription
--passwordFile password for a password-encrypted file
--password-fileRead the file password from a file, or - for stdin
--key-passphrase-fileRead your key passphrase (or recovery phrase) from a file, or - for stdin
-o, --outputOutput path. Replaces an existing file, but never the input
--forceLet 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.txt

keys

SubcommandUsageDescription
createkeys create [flags]Create a key and show its 24-word recovery phrase
listkeys listList keys: ID, type, alias, created, usage, default, expiry
aliaskeys alias <key> <alias>Set a key’s alias
deletekeys delete <key>Delete a key
exportkeys export <key> -o <file> [--format pem|raw]Export the wrapped private key (file mode 0600)
publishkeys publish --email <email> [flags]Publish your X25519 public key to the directory
unpublishkeys unpublish --email <email> [flags]Remove your key from the directory
statuskeys status [fingerprint]Check whether a key is published

<key> is a key ID or a full fingerprint.

keys create flags

FlagDescription
--aliasKey alias
--typex25519 (default) or aes256
--expires-inLifetime, for example 30d, 4w, 720h
--expires-atExpiry as an RFC 3339 timestamp
--key-passphraseKey passphrase (wins over --key-passphrase-file and MDSTN_KEY_PASSPHRASE)
--key-passphrase-fileRead the key passphrase from a file, or - for stdin
--yesSkip the 3-word recovery phrase confirmation (required without a terminal)

Directory flags

For publish, unpublish and status.

FlagDescription
--emailYour email address (publish and unpublish, required)
--kd-tokenDirectory token; wins over KD_TOKEN. Get one at keys.mdstn.dev
--server-urlDirectory URL; wins over CIPHER_SERVER_URL. Default https://keys.mdstn.dev
--fingerprintpublish: 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]
FlagDescription
--saveSave the result to the local cache
--refreshRun the discovery chain again, ignoring the cache; show any change without applying it
--yesWith --refresh: accept a changed key without asking
--jsonJSON 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-mnemonic

Asks for a 24-word recovery phrase and a new key passphrase, then rebuilds the key.

check-expiry

mdstn-cipher check-expiry

Records one notification per key that has expired or expires within 1 or 7 days. Suitable for cron.

mcp

mdstn-cipher mcp

Starts the MCP server on stdio. See MCP server.

version and completion

mdstn-cipher version [--json]
mdstn-cipher completion <bash|zsh|fish|powershell>

Environment variables

VariableUsed byEffect
MDSTN_KEY_PASSPHRASEkeys createKey passphrase, when no flag gives one
KD_TOKENkeys publish, unpublish, statusDirectory token
CIPHER_SERVER_URLkeys publish, unpublish, statusDirectory URL
CIPHER_CKD_URLlookup, encrypt --forHosted directory for lookups (staging or tests)