# Command line `cryptosuite` seals, opens, inspects, and rewraps files, for scripts, operators, and recovery work. Output is always written atomically, status is available as one JSON object, and exit codes are stable. ## A first run The configuration names the keys; the private key is passed separately, never in an argument or an environment variable. This Python snippet creates a key pair, a key configuration, and a context file: ```python import json from pathlib import Path from cryptography_suite.providers.hpke import generate_private_key, private_key_pem, public_key_text identity = generate_private_key() Path("identity.pem").write_bytes(private_key_pem(identity)) # protect this file Path("keys.json").write_text(json.dumps({ "schema_version": "cryptosuite-provider-config/1", "providers": [{ "type": "hpke", "recipients": [{"key_id": "archive", "public_key": public_key_text(identity.public_key())}], "identity": {"key_id": "archive"}, }], "keys": {"archive": {"provider_id": "cryptography-suite.hpke", "key_id": "archive"}}, "primary_key": "archive", }, indent=2)) Path("context.json").write_text(json.dumps({ "schema_version": "cryptosuite-context/1", "values": {"tenant": "acme", "purpose": "reports"}, })) Path("report.pdf").write_bytes(b"%PDF-1.7 example") ``` Seal, inspect, and open: ```console $ cryptosuite --provider-config keys.json encrypt \ --input report.pdf --output report.pdf.cse --context-file context.json encrypt: ok streaming envelope, 1 records, 1 recipient(s), not_verified policy cs-policy-v1:rYoorsHEPr6CMQWgcIBaLNfmmp3wUldtyVrG7rh_pnY $ cryptosuite inspect --input report.pdf.cse inspect: ok streaming envelope, 1 records, 1 recipient(s), not_verified policy cs-policy-v1:rYoorsHEPr6CMQWgcIBaLNfmmp3wUldtyVrG7rh_pnY $ cryptosuite --provider-config keys.json decrypt \ --input report.pdf.cse --output report-restored.pdf \ --context-file context.json --secret-stdin < identity.pem decrypt: ok streaming envelope, 1 records, 1 recipient(s), verified policy cs-policy-v1:rYoorsHEPr6CMQWgcIBaLNfmmp3wUldtyVrG7rh_pnY ``` Sealing needs only public keys, so `encrypt` reads no secret. If the private key PEM is password-protected (`private_key_pem(identity, password=...)`), `decrypt` asks for the password on the terminal; with `--non-interactive` it fails instead. On POSIX shells, `--secret-fd` reads the key from an inherited descriptor and keeps stdin free for the input: ```console $ cryptosuite --provider-config keys.json decrypt --input - --output out.pdf \ --context-file context.json --secret-fd 3 3< identity.pem < report.pdf.cse ``` ## Commands | Command | Does | Needs a private key | | --- | --- | --- | | `encrypt` | Seals `--input` to the configured keys. | No | | `decrypt` | Verifies and opens `--input`. | Yes | | `inspect` | Shows unverified metadata, offline. | No | | `rewrap` | Moves an envelope to `--destination-key`, a key name from the configuration, without decrypting the content. `--replace-key` names the recipient to replace when it is not the primary key. | Yes | | `provider health` | Checks each configured provider. | No | | `policy validate` | Checks the `--policy` document offline and prints its identifier. | No | | `doctor` | Reports versions, ML-KEM and FIPS availability, filesystem guarantees, and whether the given policy and configuration are valid. | No | | `migrate` | Moves a v3 file into a verified v4 envelope, inventories a v3 key store (`local-keystore`), or checks a v3 key file (`pem-der`) ([Migrating from version 3](migrating-from-v3.md)). A file migration is a dry run unless `--execute --backup-confirmed`. | To verify a file migration | Global options go before the command: | Option | Meaning | | --- | --- | | `--provider-config PATH` | The key configuration. | | `--policy PATH` | A policy JSON document (`Policy.to_json`); the default policy otherwise. | | `--output text\|json` | A short summary, or one `cryptosuite-status/1` JSON object, on stdout. | | `--status-file PATH` | Also write the JSON status to a new file, published atomically like any output: never over an existing file or through a link. | | `--timeout SECONDS` | Cancel after this long; the output is rolled back. | | `--non-interactive` | Never prompt. | | `--quiet` | No summary on success. | | `--log-level error\|warning\|info` | Diagnostics on stderr. | Command options: `--input PATH` (or `-` for stdin), `--output PATH`, `--overwrite` (also requires `allow_overwrite` in the policy), `--context-file PATH` (repeat to merge files; each key may appear once), and `--secret-fd FD` or `--secret-stdin`. ## Files **Key configuration** (`cryptosuite-provider-config/1`): | Field | Meaning | | --- | --- | | `providers` | A list of HPKE providers: `type` `"hpke"`, an optional `provider_id`, `recipients` (key names and public key texts), and an optional `identity` (the key name the private key from `--secret-fd` or `--secret-stdin` belongs to). | | `keys` | Names for keys: `provider_id`, `key_id`, and an optional `version`. | | `primary_key` | The name of the key every envelope is sealed to first. | | `additional_keys` | Names of further recipients, such as an escrow key. | Every key named in `keys` is trusted for opening. Unknown fields are rejected. Cloud key services are used through the Python API; the command line never imports a provider by name from a file. **Context** (`cryptosuite-context/1`): `values` maps keys to text, or to `{"base64url": "..."}` for bytes. ## Status and exit codes With `--output json`, stdout carries exactly one object: ```json {"schema_version": "cryptosuite-status/1", "command": "decrypt", "status": "ok", "operation_id": "op_...", "result": {"metadata": {"...": "..."}}, "warnings": [], "error": null} ``` On failure, `status` is `"error"` and `error` holds `code`, `category`, `message`, `retryable`, and `details`. The status never contains paths, context values, keys, or plaintext. | Exit | Meaning | | --- | --- | | 0 | Success | | 2 | Invalid arguments, configuration, or policy | | 3 | Malformed or unsupported envelope | | 4 | Authentication or context failure | | 5 | Denied by policy or key state | | 6 | Key not found, not trusted, or not capable | | 7 | Key service unavailable, timed out, or throttled | | 8 | I/O failure, or the output already exists | | 9 | Cancelled | | 10 | Migration failure: the new envelope did not verify | | 70 | Internal error | The complete contract is [RFC-0009](../v4/rfcs/RFC-0009-cli-contract.md), as implemented by [RFC-0015](../v4/rfcs/RFC-0015-cli-implementation.md).