Skip to content

CLI and file workflows

The Python wheel installs a pq-cp-abe console script. When both the native CLI and Python wheel are installed, invoke python -m pq_cp_abe to explicitly choose the Python implementation.

python -m pq_cp_abe --help
python -m pq_cp_abe encrypt --help
python -m pq_cp_abe --version
python -m pq_cp_abe --test

Commands include setup, genkey, encrypt, decrypt, buffer operations, CoverCrypt authority growth and version. Both positional commands and named --setup / --encrypt forms are supported.

CoverCrypt configuration

Create an attribute definition:

{
  "dimensions": [
    {"name": "department", "attributes": ["finance", "it"]},
    {"name": "level", "attributes": ["user", "admin"]}
  ]
}

Save as dimensions.json. With the Python CLI you can pass --config dimensions.json on setup. You may also set HCPABE_COVERCRYPT_CONFIG and HCPABE_COVERCRYPT_MODE yourself. The CLI has --mode hybridized|post_quantum|classic (default hybridized).

Unsigned file workflow

Create a directory keys first and a plaintext file message.txt. The following uses the Python CLI and named options:

python -m pq_cp_abe --setup --scheme covercrypt --config dimensions.json --file keys
python -m pq_cp_abe --genkey --scheme covercrypt --master-key keys/cpabe_msk.key --attributes "department::finance" --user-key finance.key
python -m pq_cp_abe --encrypt --scheme covercrypt --public-key keys/cpabe_pk.key --file message.txt --policy "department::finance" --ciphertext message.enc
python -m pq_cp_abe --decrypt --user-key finance.key --ciphertext message.enc --output recovered.txt

The setup path can be an existing directory, or a prefix when using the underlying native naming convention. See python -m pq_cp_abe setup --help for command syntax.

Signing workflow

python -m pq_cp_abe --setup --scheme covercrypt --config dimensions.json --file signed --with-signing-keys --ml-dsa 65
python -m pq_cp_abe --genkey --scheme covercrypt --master-key signed_msk.key --attributes "department::finance" --user-key signed-user.key
python -m pq_cp_abe --encrypt --scheme covercrypt --sign --public-key signed_pk.key --signing-key signed_ml-dsa_sk.key --file message.txt --policy "department::finance" --ciphertext signed.enc --aes-bits 192 --ml-dsa 65
python -m pq_cp_abe --decrypt --verify --user-key signed-user.key --verification-key signed_ml-dsa_pk.key --ciphertext signed.enc --output verified.txt
  • --with-signing-keys: add an ML-DSA keypair during setup; does not sign the ABE keys.
  • --sign: sign data in the encryption flow.
  • --verify: decrypt and require valid signature verification.
  • --ml-dsa {44,65,87}: choose set when generating signing keys or signing (default 87).
  • --aes-bits {128,192,256}: choose AES size for encryption (default 256).
  • The older --pqc/setup-pqc aliases are supported for compatibility but are less descriptive.

When setup uses --with-signing-keys, the new signature files use the ml-dsa label; legacy naming may use pqc. Keys are not interchangeable across ML-DSA parameter sets.

Python API file functions

If you do not want to invoke the CLI, the functional API exposes setup_files, setup_files_with_signing, generate_secret_key_file, encrypt_file and decrypt_file. These operate on native host paths and raise typed Python errors.

CoverCrypt's file-based key issuing persists authority/tracing metadata; coordinate concurrent writes to the same master key. For raw C ABI commands and installation of the standalone native executable, see the repository CLI guide.

Platform notes

On Windows CMD, use set HCPABE_COVERCRYPT_CONFIG=...; in PowerShell use $env:HCPABE_COVERCRYPT_CONFIG = "..."; in Bash use export HCPABE_COVERCRYPT_CONFIG=.... Passing --config avoids depending on shell syntax.

Embedded PDF signatures and document encryption

The Python CLI mirrors the native and Node/WASM command surface for embedded document signatures:

python -m pq_cp_abe signature_keygen mldsa65-ed25519 signing.key signing.pub
python -m pq_cp_abe signature_csr signing.key "CN=User" user.csr
python -m pq_cp_abe signature_cert --valid-days 365 signing.key "CN=User" user.der
python -m pq_cp_abe document_sign signing.key user.der input.pdf signed.pdf
python -m pq_cp_abe document_verify user.der signed.pdf
python -m pq_cp_abe document_encrypt --scheme ac17 cpabe_pk.key signing.key user.der input.pdf "admin and it" document.ct
python -m pq_cp_abe document_decrypt user.key user.der document.ct recovered.pdf
python -m pq_cp_abe ciphertext_sign --metadata request-123 signing.key document.ct document.env
python -m pq_cp_abe ciphertext_verify --metadata request-123 mldsa65-ed25519 signing.pub document.env recovered.ct

The seven selectors are mldsa44, mldsa65, mldsa87, mldsa44-ed25519, mldsa65-ed25519, mldsa87-ed448 and mldsa87-ecdsa-p384. document_countersign implements the trusted-server workflow; document_migrate verifies a legacy signed ciphertext before creating a new embedded signature. PDF verification supports --index, --at and --allow-old-revision.

The exported signing private-key file is the SDK's unencrypted expanded-key format, not PKCS#8. Protect it as a secret. signature_cert creates a local self-signed certificate; production trust, revocation and replay policy remain application responsibilities.