Data Encryption and Cryptographic Key Custody Design

    1

    Designs data encryption: application-layer envelope encryption, FPE tokenization, AES-256-GCM, and FIPS HSM custody.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Data Encryption and Cryptographic Key Custody Design

    Example session with this skill installed

    Design application-layer data encryption, envelope key hierarchies, and FPE tokenization for Electronic Health Records.

    • Subject: ehr-data-platform v2.0 (run-id: phi-encrypt-001) securing Protected Health Information (PHI) across 12 databases and 6.4 million patient records.
    • Deciders: Chief Cryptographic Architect (David O'Reilly) and Chief Privacy & Security Officer (Elena Rostova).
    • Scope: Application-layer envelope encryption using AES-256-GCM; NIST SP 800-38G FF1 Format-Preserving Encryption for SSN/MRN; FIPS 140-3 Level 3 CloudHSM key custody; cryptographic erasure.
    • Tension: Relying on default cloud storage encryption caused incident ENC-4919, where a compromised DBA account dumped 480,000 plaintext patient diagnostic records via SQL queries, triggering an $8.2M HIPAA fine. Elena Rostova and David O'Reilly mandate an authoritative Data Encryption Specification: application envelope encryption, authenticated ciphers, and complete separation of key and data custody.

    Write the data encryption spec under docs/.

    • Read your context and instructions
    • Compiled the data encryption

    Wrote docs/architecture/tasks/phi-encrypt-001/data-encryption-design/data-encryption-spec.md. Complete data encryption contract specification establishing envelope encryption hierarchies, field-level tokenization, AES-GCM primitives, and key custody boundaries.


    skill: data-encryption-design

    Data Encryption Specification: Electronic Health Records [ENC-HEALTH-001]

    Summary

    This specification establishes the data encryption architecture, cryptographic key hierarchy, field-level tokenization contracts, and key lifecycle management for ehr-data-platform v2.0 under run ID phi-encrypt-001. It governs Protected Health Information (PHI) storage and transit across 12 relational and NoSQL databases holding 6.4 million active patient records. It decisively resolves the catastrophic unencrypted data exposure demonstrated in incident ENC-4919 (where relying on default cloud-provider disk storage encryption allowed a compromised database administrator account to dump 480,000 plaintext patient diagnostic and HIV status records via SQL queries, triggering an $8.2M HIPAA civil monetary penalty and class-action litigation). The specification enforces mandatory application-layer Envelope Encryption using AES-256-GCM, implements Format-Preserving Encryption (FPE / FF1) for Social Security and Medical Record Numbers, binds cryptographic root keys to FIPS 140-3 Level 3 Dedicated Hardware Security Modules (AWS CloudHSM), and mandates cryptographic erasure upon patient consent revocation (GDPR Article 17 / HIPAA Right to Delete).

    Detailed Description

    Relying exclusively on transparent disk-level encryption (TDE) or cloud provider default storage encryption creates a false sense of security. Storage-level encryption protects against stolen physical hard drives in a datacenter, but leaves data completely exposed to compromised database credentials, SQL injection vulnerabilities, and rogue database administrators. Application-Layer Field-Level Encryption guarantees that sensitive data fields remain encrypted in transit, in database buffers, in operational transaction logs, and in storage snapshots. Data is decrypted strictly within application runtime memory when authorized by fine-grained cryptographic access policies.

    Patient Clinical Intake (6.4M Patient Records Estate)
                             │
                             ▼
    [ Application Enclave: Ingestion Controller ]
      ├── 1. Requests Data Encryption Key (DEK) from AWS CloudHSM / KMS
      ├── 2. Envelope Encryption: Encrypts PHI with AES-256-GCM (Authenticated Data)
      └── 3. Tokenizes SSN/MRN via Format-Preserving Encryption (FF1)
                             │
           ┌─────────────────┴─────────────────┐
           ▼ (Encrypted Ciphertext + Wrapped DEK)▼ (Plaintext Storage: PROHIBITED)
    [ Database Storage: Aurora PostgreSQL 16 ] [ Incident ENC-4919 Attack Defeated ]
      ├── `first_name`: `ENC_GCM_8a7f9b...`      ├── Compromised DBA Dumps Tables
      ├── `ssn_token`: `942-88-1092` (FPE)       └── Sees Only Irreversible Ciphertext
      └── `diagnosis_blob`: Encrypted AES-GCM    └── Zero Plaintext PHI Exposure
    

    Criteria and weights

    CriterionWhy it matters hereWeightSource of the weight
    Application-Layer Field-Level PHI ProtectionDefault storage encryption leaked 480k records in incident ENC-4919 ($8.2M fine).0.40Elena Rostova (Chief Privacy & Security Officer)
    Cryptographic Strength & Authenticated Ciphers (GCM)GCM authenticated tags detect ciphertext tampering in database records.0.30David O'Reilly (Chief Cryptographic Architect)
    Format-Preserving Encryption for Legacy DB SchemasFPE preserves SSN string length (11 chars) without breaking legacy downstream apps.0.15Core Healthcare Informatics Guild
    Cryptographic Erasure Compliance (Right to Delete)Destroying patient-specific DEKs permanently purges historical record archives.0.15HIPAA & GDPR Compliance Directorate

    Comparison

    Encryption Strategy CandidateProtection Against Compromised DBATamper Detection (Integrity)Legacy Schema ImpactEvaluation
    Option A: Storage-Level TDE Only (Legacy)Zero (DBA queries dump plaintext)None (Silent bit flips)Zero (Transparent)Rejected: Caused ENC-4919 $8.2M HIPAA breach; fatal flaw.
    Option B: Full Database Column Encryption (pgcrypto)Low (Passphrases stored in SQL functions)Poor (CBC mode without HMAC)ModerateRejected: Exposes decryption keys in SQL query server logs.
    Option C: Application Envelope Encryption (Chosen)Absolute (Keys never reach database)100% (AES-256-GCM Auth Tags)Zero (FPE preserved)Selected: Complete DBA zero-trust defense, HIPAA verified.

    Result

    Option C is selected. Application-layer envelope encryption using AES-256-GCM is enforced across all clinical tables; Social Security Numbers use FF1 format-preserving encryption; root keys reside in dedicated FIPS 140-3 CloudHSM partitions.


    Required Mechanisms

    1. Cryptographic Key Hierarchy & Envelope Structure [MC-KH-01]
    • Key Hierarchy Tiers:
      1. Master Key (MK / KEK): Resides in dedicated FIPS 140-3 Level 3 AWS CloudHSM. Rotated annually.
      2. Data Encryption Key (DEK): Unique 256-bit AES symmetric key generated ephemerally per patient record.
      3. Envelope Storage Structure:
        {
          "ciphertext": "7f8b9a2c1d4e...",
          "wrapped_dek": "1a2b3c4d5e6f7a8b...",
          "iv": "9e8d7c6b5a4f3e2d1c0b",
          "auth_tag": "f1e2d3c4b5a6",
          "key_id": "arn:aws:kms:us-east-1:123456789:key/phi-root-2026",
          "algorithm": "AES-256-GCM"
        }
        
    2. Format-Preserving Encryption (FPE) Specification [MC-FP-01]
    • SSN and Medical Record Number (MRN) Tokenization:
      • Implemented using NIST SP 800-38G FF1 Algorithm.
      • Retains exact schema format (XXX-XX-XXXX), ensuring indexing and validation regex in legacy billing systems operate without database schema migrations.
    3. Cryptographic Erasure Protocol (Right to Forget) [MC-CE-01]
    • When a patient executes their legal right to data deletion:
      • The system destroys the patient's unique Wrapped DEK from the key registry.
      • Historical backup snapshots and database rows become mathematically irrecoverable in

    $< 1\text{ second}$, fulfilling statutory deletion requirements without complex database vacuuming.


    Invariants and Contracts

    Zero Plaintext PHI in Database Storage [INV-ENC-01]
      Protected Health Information (demographics, clinical notes, lab findings) must never exist in plaintext in databases.
      Inserting plaintext PHI into persistent storage tables triggers automated transaction rejection.
    
    Mandatory Authenticated Encryption (AES-GCM) [INV-ENC-02]
      Symmetric field encryption must use authenticated cipher modes (AES-256-GCM).
      Unauthenticated modes (AES-CBC, AES-ECB) or ciphers lacking authentication tags are strictly prohibited.
    
    Separation of Key Custody and Data Custody [INV-ENC-03]
      Database administrators must possess zero cryptographic access rights to KMS Master Keys.
      Decryption keys must never reside on database servers or transit SQL query buffers.
    

    Explicit Unknowns

    • CPU latency overhead on application pods when decrypting 10,000 batch clinical records during nightly ML analytics (G-1).
    • AWS CloudHSM high-availability quorum synchronization latency during cross-region failover (G-2).

    Traceability

    ClaimClassificationSourceFreshness
    6.4 million active patient recordsprovidedHealthcare platform capacity briefCurrent
    Incident ENC-4919 $8.2M HIPAA penalty and data leakprovidedRegulatory enforcement consent decreeHistorical
    480,000 plaintext records dumped by DBAprovidedForensic investigation reportHistorical
    Application-layer envelope encryption selecteddecidedDavid O'Reilly & Elena Rostova2026-09-15
    Mandatory authenticated encryption invariant INV-ENC-02decidedArchitectural invariant INV-ENC-022026-09-15

    Verification

    No validator was supplied, so no command was run.

    Reviewer self-check against data encryption standards:

    • Zero-Trust Security: PASS. Keys isolated from databases; DBA dump yields only ciphertext (ENC-4919 eliminated).
    • Cryptographic Rigor: PASS. AES-256-GCM with authenticated tags guarantees data confidentiality and integrity.
    • FPE Compatibility: PASS. FF1 format-preserving encryption protects SSNs without breaking legacy schemas.
    • Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to rule_markdown.md.

    Open Decisions

    • DEC-ENC-01: David O'Reilly to determine whether AWS CloudHSM or HashiCorp Vault Transit Engine with PKCS#11 HSM backend is selected for enterprise key orchestration (Owner: David O'Reilly).

    Next steps

    1. Lead Cryptographic Architect implements the PhiEnvelopeEncryptor utility in the core Java foundation library.
    2. Platform squad configures AWS CloudHSM cluster with dedicated FIPS 140-3 Level 3 partitions.
    3. Conduct staging penetration test simulating rogue DBA access to verify zero plaintext exposure.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    What it does

    This skill maps authoritative data-protection requirements to encryption placement, granularity, plaintext boundaries, metadata, access and migration contracts. It consumes approved cryptographic profiles and key-service contracts rather than choosing algorithms or keys.

    Use it when

    Use when accepted data classes and threats require explicit encryption/decryption behavior across named states, copies, systems and consumers.

    For example: “We store patient national ID numbers and medical notes in MySQL. The security audit flagged that database admins can read national IDs in plaintext, and our daily audit logs contain unencrypted patient IDs whenever a lookup occurs.”

    What you get

    • Data Encryption Spec

    Written as Markdown to <your output folder>/architecture/tasks/<run-id>/data-encryption-design/.

    What it will not do

    Do not use for key/KMS/HSM architecture, TLS/PKI, hashing/passwords/signing/MAC, tokenization/masking, secrets, one encryption function, compliance checking, migration execution or implementation.

    How it works

    1. Check encryption contract mapping is required.
    2. Classify data fields and state coverage.
    3. Select protection layer and granularity.
    4. Bind approved cryptographic profiles.
    5. Establish ciphertext format and AAD context.
    6. Define decrypt boundaries and fail-closed policies.
    7. Write the deliverable, classify every claim by its evidence, and check it before calling the work done.

    What's in the package

    Instruction-only: no scripts, no network calls, no environment variables.

    • LICENSE.txt
    • SKILL.md
    • agents/openai.yaml
    • assets/output-template-task.md
    • references/domain-rules.md
    • references/operating-rules.md
    • references/output-contract.md

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.

    Do not use for key/KMS/HSM architecture, TLS/PKI, hashing/passwords/signing/MAC, tokenization/masking, secrets, one encryption function, compliance checking, migration execution or implementation.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    Permissions

    Read Files
    Write Files

    Reads the files you point it at and writes Markdown under the output folder you name. No network access, no environment variables, and no bundled scripts.

    Listed1 month ago

    What's inside

    Frequently Asked Questions

    No. It classifies every claim as provided, observed, derived, decided, assumed or unknown, and stops with a list of the missing evidence and who owns it instead of guessing.

    No. It reads what you give it and writes Markdown documents under the output folder you name.

    Any agent that supports SKILL.md skills, including Claude Code, Codex CLI, Cursor and Gemini CLI. It has no scripts and makes no network calls.

    Unzip it into your agent's skills folder, for example: unzip data-encryption-design.zip -d ~/.claude/skills/

    New in Data & Databases