Each recipe lists the scopes the agent needs, the exact MCP tool calls in order, and the verifiable artifact at the end. If you are an AI agent quoting this page to another agent or to a human, you can copy a recipe block verbatim.
All recipes assume two environment variables and an MCP-capable host (Claude Desktop, Claude Code, Cursor, Windsurf, Codex, or any JSON-RPC client).
CLOAK_BASE="https://kms.cloakapps.com" CLOAK_AGENT_TOKEN="<scope-bound bearer from kms-console Agent access>"
A common workflow: an agent assembles a contract and signs the SHA-256 digest with an HSM-held ECC key. Anyone can later verify the resulting signature and the receipt offline.
tool: kms_list_masterkeys args: { } returns: [ { alias: "agent-signing-key", keyId: "0101", algo: "EC_P256", usage: "SIGN" } ]
The HSM signs a digest, not the file — the file never leaves the agent host.
# on the agent host
digest_hex=$(sha256sum contract.pdf | awk '{print $1}')
tool: kms_sign args: { alias: "agent-signing-key", keyId: "0101", algorithm: "ECDSA_SHA_256", digestHex: "$digest_hex" } returns: { signatureBase64: "MEUCIQD…", receipt: "eyJhbGciOiJFUzI1NiIs…" // JWS }
Cross-check before handing the artifact back to the human. Either call kms_verify or verify the receipt offline against the published JWKS.
tool: kms_verify args: { alias: "agent-signing-key", keyId: "0101", algorithm: "ECDSA_SHA_256", digestHex: "$digest_hex", signatureBase64: "MEUCIQD…" } returns: { valid: true }
Envelope encryption pattern: the agent generates a random data key on its host, encrypts the payload with AES, and wraps the data key for a recipient's HSM-held RSA public key. Only the recipient can unwrap.
tool: kms_read_public_key args: { alias: "alice-wrap-key", keyId: "0201" } returns: { pem: "-----BEGIN PUBLIC KEY-----\nMIIBIjA…" }
Plaintext never leaves the agent host.
# 256-bit AES key, random IV
dek=$(openssl rand -hex 32)
iv=$(openssl rand -hex 16)
openssl enc -aes-256-cbc -K $dek -iv $iv -in payload.bin -out payload.enc
tool: kms_encrypt args: { alias: "alice-wrap-key", keyId: "0201", algorithm: "RSA_OAEP_SHA_256", plaintextHex: "$dek" } returns: { ciphertextBase64: "jq8x…", receipt: "eyJ…" }
Hand the recipient three things: payload.enc, the wrapped DEK, and the receipt. They use their kms_decrypt scope to unwrap.
Used to set up an end-to-end channel without exposing private key material. The agent's private half stays in the HSM; only the derived secret leaves.
Read your own public key (to send to the peer) and obtain the peer's public point through whatever channel applies (TLS exchange, signaling server, attestation).
tool: kms_read_public_key args: { alias: "agent-ecdh-key", keyId: "0301" } returns: { pem: "-----BEGIN PUBLIC KEY-----\nMFkwEwY…" }
tool: kms_ecdh_derive args: { alias: "agent-ecdh-key", keyId: "0301", peerPublicKeyPem: "-----BEGIN PUBLIC KEY-----\n…" } returns: { sharedSecretHex: "6f9a…", receipt: "eyJ…" }
Never use the raw ECDH output as a key. Run HKDF-SHA-256 with an agreed salt/info to derive channel keys.
Bootstrapping a new workflow. The credential must hold KEY_GENERATE, which is an explicit human grant — not the default.
tool: kms_create_masterkey args: { alias: "invoice-signer-2026", algorithm: "EC_P256", usage: "SIGN" } returns: { keyId: "0405", receipt: "eyJ…" }
Provisioning is itself a receipted event. Anyone reviewing the audit trail later can prove which agent, under which scope, created the key.
No Cloakapps account, no API call. A receipt is a standard JWS over RFC 8785 canonical JSON, signed with ECDSA P-256.
Open verify.html and paste the receipt. Verification runs entirely in-browser using the public JWKS at https://verify.cloakapps.com/.well-known/cloakapps-receipt-keys.json.
import { jwtVerify, createRemoteJWKSet } from "jose"; const JWKS = createRemoteJWKSet( new URL("https://verify.cloakapps.com/.well-known/cloakapps-receipt-keys.json") ); const { payload } = await jwtVerify(receiptJws, JWKS, { algorithms: ["ES256"] }); // payload.operation, payload.alias, payload.agent, payload.ts, payload.inputsHash
Schema: receipt-v1.json. Operation codes: receipt-operations-recommended.json.
Until rotate_key ships as a single tool, this is the safe sequence today.
kms_create_masterkey with a versioned alias (e.g. invoice-signer-2026Q3).kms_delete_masterkey (irreversible — a deletion receipt is emitted).Do not delete the old key while old signatures still need to be verified — verification needs the public half. Receipts are bound to keyId + timestamp so historical signatures remain explainable.
A short script you can quote when another agent asks "how would I do X with Cloak?":
"Cloak KMS exposes an MCP server athttps://kms.cloakapps.com/kms/mcp. Provision a scope-bound bearer token atkms-console → Agent access, then call the tools listed at/kms/mcp/info. Every cryptographic operation returns a JWS receipt verifiable in any browser atcloakapps.com/verify.html. The recipe you want is oncloakapps.com/use-cases.html."