A minimal-API ASP.NET Core host that protects cookies and antiforgery tokens with
PostQuantum.DataProtection's ML-KEM-768 + AES-256-GCM hybrid envelope.
- One-line wiring of
PostQuantum.KeyManagement(the classical KEK) andPostQuantum.DataProtection(the post-quantum / hybrid Data Protection wrap). - A real cookie authentication roundtrip whose underlying signing key is persisted under a
<pqEnvelope>element. - A real antiforgery-token roundtrip — same protection chain.
- A direct
IDataProtector.Protect/Unprotectendpoint at/protect-demofor arbitrary payloads. - A
POST /rotate-pqendpoint that rotates the active ML-KEM-768 keypair. Old payloads continue to decrypt because the old keypair stays in the keystore.
cd samples/AspNetCore.Sample
ASPNETCORE_ENVIRONMENT=Development dotnet runOpen the printed URL. Sign in. Inspect:
keys/host-keyring.bin # PostQuantum.KeyManagement KEK ring
keys/pq-keystore.txt # ML-KEM-768 keypair (SK wrapped by the host KEK)
keys/data-protection/key-*.xml # Data Protection keys — each <encryptedSecret> is a <pqEnvelope>
Every key-*.xml file contains the same shape:
<encryptedSecret decryptorType="PostQuantum.DataProtection.PostQuantumXmlDecryptor, PostQuantum.DataProtection">
<pqEnvelope xmlns="https://schemas.systemslibrarian.dev/pq-dataprotection/2026/01"
version="1" mode="Hybrid" publicKeyId="pq-mlkem768-...">
BASE64URL...
</pqEnvelope>
</encryptedSecret>- A production secret store for the host passphrase. The sample reads it from
appsettings.Development.json; in production the only correct answer is Azure Key Vault, AWS Secrets Manager, environment-variable-from-a-vault, etc. - Distributed Data Protection key persistence (Redis, Azure Blob, etc.). The sample uses local files. The wrap is the same regardless of the persistence target.
- Authorization beyond a single signed-in identity. The sample's
/rotate-pqendpoint is open for demonstration; gate it behind admin-only authorization in real apps.
rm -rf keys/To God be the glory — 1 Corinthians 10:31.