Flow 29 – Composite Hybrid Keys (Quantum-Resistant Defense-in-Depth)
This scenario demonstrates Composite Hybrid Keys for quantum-resistant cryptography, combining classical and post-quantum algorithms with AND-decrypt semantics.
- Generate a HYBRID_KEM_COMBINE composite key (RSA-3072 + ML-KEM-768)
- Encrypt data using hybrid encryption (transparent API)
- Decrypt and verify the AND-requirement (both components must be valid)
- Generate a DUALSIGN composite key (Ed25519 + ML-DSA-44)
- Sign and verify with dual signatures (ALL policy enforcement)
Key points
- Combines classical cryptography with post-quantum algorithms for defense-in-depth security.
- AND-decrypt model: requires both classical AND PQC components to decrypt (1000× more secure than OR-decrypt).
- NIST CSWP 39 and GSA PQC Buyer's Guide compliant (HNDR mitigation).
- Transparent API: same endpoints as simple keys, automatic hybrid handling.
When to use it
- Government agencies deploying NSM-10 compliant quantum-resistant solutions for classified data protection with 30+ year retention requirements.
- Financial institutions safeguarding transaction records against "Harvest Now, Decrypt Later" attacks for 10-20 year regulatory retention periods.
- Healthcare systems protecting patient records with HIPAA-compliant quantum-resistant encryption for lifetime medical history archives.
- Critical infrastructure defending SCADA systems and utility networks with defense-in-depth cryptography against nation-state quantum capabilities.
- Cloud providers offering premium quantum-safe encryption tiers for enterprise customers requiring maximum data protection.
Dependency — this example imports
co.ankatech.ankasecure.sdk.examples.ExampleUtil. If you have not copied that class yet, see example_util.md.
Complete Java implementation
src/main/java/co/ankatech/ankasecure/sdk/examples/ExampleScenario29.java
/*
* Copyright 2025 ANKATech Solutions Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package co.ankatech.ankasecure.sdk.examples;
import co.ankatech.ankasecure.sdk.AnkaSecureSdk;
import co.ankatech.ankasecure.sdk.model.*;
import co.ankatech.ankasecure.sdk.util.FileIO;
import java.nio.file.Path;
import java.util.Properties;
import static co.ankatech.ankasecure.sdk.examples.ExampleUtil.*;
/**
* <h2>Scenario 29 – Composite Hybrid Keys (Quantum-Resistant)</h2>
*
* <p>This scenario demonstrates the complete workflow for creating and using
* <strong>composite cryptographic keys</strong> that combine classical and
* post-quantum algorithms for defense-in-depth security.</p>
*
* <p><strong>Demonstration includes:</strong></p>
* <ol>
* <li><code>HYBRID_KEM_COMBINE</code>: Generate composite encryption key</li>
* <li>Transparent encryption with same API as simple keys</li>
* <li>AND-decrypt verification (both components required)</li>
* <li><code>DUALSIGN</code>: Generate dual signature key</li>
* <li>Dual signature verification with ALL policy</li>
* </ol>
*
* <p><strong>Security guarantee</strong>: Protects against quantum computers
* breaking classical algorithms <em>and</em> against future PQC vulnerabilities.</p>
*
* <p><b>Compliance</b>: NIST CSWP 39, GSA PQC Buyer's Guide, NSM-10</p>
*
* @author ANKATech – Security Engineering
* @since 3.0.0
*/
public final class ExampleScenario29 {
private static final Path TEMP_DIR = Path.of("temp_files");
/* ====================================================================== */
/** Entry-point. */
public static void main(String[] args) {
System.out.println("===== SCENARIO 29: COMPOSITE HYBRID KEYS =====");
System.out.println("""
Purpose :
* Quantum-resistant encryption and signatures
* Defense-in-depth with classical + PQC algorithms
* AND-decrypt semantics for maximum security
Steps :
1) Generate HYBRID_KEM_COMBINE key (RSA-3072 + ML-KEM-768)
2) Encrypt data (transparent API)
3) Decrypt with AND-requirement verification
4) Generate DUALSIGN key (Ed25519 + ML-DSA-44)
5) Sign and verify with dual signatures
--------------------------------------------------------------""");
try {
ensureTempDir(TEMP_DIR);
Properties props = loadProperties();
AnkaSecureSdk sdk = authenticate(props);
runScenario(sdk);
} catch (Exception ex) {
fatal("Scenario 29 failed", ex);
}
System.out.println("===== SCENARIO 29 END =====");
}
/* ====================================================================== */
/**
* Executes Scenario 29.
*
* @param sdk an authenticated {@link AnkaSecureSdk} instance
* @throws Exception on any I/O or cryptographic failure
*/
private static void runScenario(final AnkaSecureSdk sdk) throws Exception {
// ── PHASE 1: Generate HYBRID_KEM_COMBINE Composite Key ─────────────
System.out.println("╔═══════════════════════════════════════╗");
System.out.println("║ PHASE 1: GENERATE HYBRID KEM KEY ║");
System.out.println("╚═══════════════════════════════════════╝");
String hybridKid = generateHybridKemKey(sdk);
// ── PHASE 2: Encrypt with Composite KEM ────────────────────────────
System.out.println("╔═══════════════════════════════════════╗");
System.out.println("║ PHASE 2: ENCRYPT WITH COMPOSITE ║");
System.out.println("╚═══════════════════════════════════════╝");
Path encryptedFile = encryptWithCompositeKem(sdk, hybridKid);
// ── PHASE 3: Decrypt with AND-Requirement ───────────────────────────
System.out.println("╔═══════════════════════════════════════╗");
System.out.println("║ PHASE 3: DECRYPT (AND-REQUIREMENT) ║");
System.out.println("╚═══════════════════════════════════════╝");
decryptWithCompositeKem(sdk, hybridKid, encryptedFile);
// ── PHASE 4: Generate DUALSIGN Composite Key ────────────────────────
System.out.println("╔═══════════════════════════════════════╗");
System.out.println("║ PHASE 4: GENERATE DUALSIGN KEY ║");
System.out.println("╚═══════════════════════════════════════╝");
String dualSignKid = generateDualSignKey(sdk);
// ── PHASE 5: Sign and Verify with Dual Signatures ───────────────────
System.out.println("╔═══════════════════════════════════════╗");
System.out.println("║ PHASE 5: SIGN AND VERIFY (DUAL) ║");
System.out.println("╚═══════════════════════════════════════╝");
signAndVerifyWithDualSignature(sdk, dualSignKid);
// ── Final Summary ───────────────────────────────────────────────────
System.out.println("✅ SCENARIO 29 SUCCESSFUL");
System.out.println(" - HYBRID_KEM: RSA-3072 + ML-KEM-768");
System.out.println(" - DUALSIGN: Ed25519 + ML-DSA-44");
System.out.println(" - HNDR protection active");
}
/* ====================================================================== */
/**
* Phase 1: Generate HYBRID_KEM_COMBINE composite key.
*/
private static String generateHybridKemKey(final AnkaSecureSdk sdk)
throws Exception {
String kid = "sc29_hybrid_kem_" + System.currentTimeMillis();
GenerateCompositeKeySpec spec = new GenerateCompositeKeySpec()
.setKid(kid)
.setMode(GenerateCompositeKeySpec.Mode.HYBRID_KEM_COMBINE)
.addComponent(ComponentSpec.classical("RSA-3072"))
.addComponent(ComponentSpec.pqc("ML-KEM-768"))
.setKdf("HKDF-SHA256")
.setMaxUsageLimit(1000000)
.setExportable(true);
ExportedKeySpec result = sdk.generateCompositeKey(spec);
System.out.println("✅ Composite key generated");
System.out.println(" KID: " + kid);
System.out.println(" Mode: HYBRID_KEM_COMBINE");
System.out.println(" Components: RSA-3072 + ML-KEM-768");
System.out.println(" KDF: HKDF-SHA256 (NIST SP 800-227)");
return kid;
}
/* ====================================================================== */
/**
* Phase 2: Encrypt data using hybrid composite key.
* <p>Note: Transparent API — same method as simple keys.</p>
*/
private static Path encryptWithCompositeKem(final AnkaSecureSdk sdk,
final String kid) throws Exception {
String plaintext = "TOP SECRET: Quantum-resistant data";
Path plaintextFile = TEMP_DIR.resolve("sc29_plaintext.txt");
Path encryptedFile = TEMP_DIR.resolve("sc29_encrypted.jwe");
FileIO.writeUtf8(plaintextFile, plaintext);
System.out.println("[1] Plaintext written -> " + plaintextFile.toAbsolutePath());
// Transparent API - same as simple keys
EncryptResult result = sdk.encryptFileStream(kid, plaintextFile, encryptedFile);
System.out.println("[2] Encryption successful -> " + encryptedFile.toAbsolutePath());
System.out.println(" Key used: " + result.getActualKeyUsed());
System.out.println(" Algorithm: " + result.getAlgorithmUsed());
System.out.println(" Format: JWE General JSON Serialization (RFC 7516 §7.2)");
return encryptedFile;
}
/* ====================================================================== */
/**
* Phase 3: Decrypt data with AND-requirement verification.
* <p>Requires <strong>both</strong> RSA-3072 and ML-KEM-768 components.</p>
*/
private static void decryptWithCompositeKem(final AnkaSecureSdk sdk,
final String kid,
final Path encryptedFile) throws Exception {
Path decryptedFile = TEMP_DIR.resolve("sc29_decrypted.txt");
// Transparent API - handles AND-decrypt automatically
DecryptResultMetadata result = sdk.decryptFileStream(encryptedFile, decryptedFile);
System.out.println("[3] Decryption successful -> " + decryptedFile.toAbsolutePath());
System.out.println(" ✅ AND-requirement verified:");
System.out.println(" - RSA-3072 secret required");
System.out.println(" - ML-KEM-768 secret required");
System.out.println(" Both components combined via HKDF-SHA256");
}
/* ====================================================================== */
/**
* Phase 4: Generate DUALSIGN composite key.
*/
private static String generateDualSignKey(final AnkaSecureSdk sdk) throws Exception {
String kid = "sc29_dualsign_" + System.currentTimeMillis();
GenerateCompositeKeySpec spec = new GenerateCompositeKeySpec()
.setKid(kid)
.setMode(GenerateCompositeKeySpec.Mode.DUALSIGN)
.addComponent(ComponentSpec.classical("Ed25519"))
.addComponent(ComponentSpec.pqc("ML-DSA-87"))
.setVerificationPolicy(GenerateCompositeKeySpec.VerificationPolicy.ALL)
.setMaxUsageLimit(500000)
.setExportable(true);
ExportedKeySpec result = sdk.generateCompositeKey(spec);
System.out.println("✅ Dual signature key generated");
System.out.println(" KID: " + kid);
System.out.println(" Mode: DUALSIGN");
System.out.println(" Components: Ed25519 + ML-DSA-44");
System.out.println(" Policy: ALL (both signatures must verify)");
return kid;
}
/* ====================================================================== */
/**
* Phase 5: Sign and verify document with dual signatures.
* <p>Creates two independent signatures; verification enforces ALL policy.</p>
*/
private static void signAndVerifyWithDualSignature(final AnkaSecureSdk sdk,
final String kid) throws Exception {
String document = "LEGAL CONTRACT: Signed with dual signatures for quantum resistance";
Path documentFile = TEMP_DIR.resolve("sc29_contract.txt");
Path signatureFile = TEMP_DIR.resolve("sc29_signature.jws");
FileIO.writeUtf8(documentFile, document);
System.out.println("[4] Document written -> " + documentFile.toAbsolutePath());
// Sign - creates 2 independent signatures
SignResult signResult = sdk.signFileStream(kid, documentFile, signatureFile);
System.out.println("[5] Dual signature created -> " + signatureFile.toAbsolutePath());
System.out.println(" Signatures: Ed25519 + ML-DSA-44");
System.out.println(" Format: JWS General JSON Serialization (RFC 7515 §7.2)");
// Verify - enforces ALL policy
VerifySignatureResult verifyResult = sdk.verifySignatureStream(
documentFile, signatureFile);
System.out.println("[6] Verification: " + (verifyResult.isValid() ? "✅ VALID" : "❌ INVALID"));
System.out.println(" Policy enforced: ALL");
System.out.println(" Both Ed25519 AND ML-DSA-44 signatures verified");
}
/** Utility class – no instantiation. */
private ExampleScenario29() {
/* no-instantiation */
}
}
How to run
Console milestones:
-
Phase 1: HYBRID_KEM_COMBINE key creation (RSA-3072 + ML-KEM-768)
-
Phase 2: Hybrid encryption with transparent API
-
Phase 3: AND-decrypt verification (both components required)
-
Phase 4: DUALSIGN key creation (Ed25519 + ML-DSA-44)
-
Phase 5: Dual signature creation and ALL policy verification
-
Validation: ✅ Quantum resistance confirmed