AI agents handle some of the most sensitive text in modern software: internal documents, M&A notes, medical records, API context, and multi-turn chat histories. Most teams store those logs in a standard database encrypted at rest with a single cloud KMS key — or worse, in plaintext — using classical RSA/ECC key exchange.

That creates two real architectural problems:

  1. Harvest Now, Decrypt Later (HNDL): Adversaries can capture encrypted traffic or archives today and decrypt them once cryptanalytically relevant quantum computers arrive. For regulated data with a 10–30 year retention window (for example under the UAE National Encryption Policy and DESC post-quantum guidelines), waiting until the last minute isn't viable.
  2. Single-point key custody: If a single server or KMS admin credential is compromised, every stored prompt and conversation falls with it.

In this guide, we'll encrypt and decrypt AI agent prompts in TypeScript using NIST FIPS 203 (ML-KEM-768) paired with AES-256-GCM, without your backend ever holding a private key.

How the Architecture Works

We'll use cifer-sdk from CIFER, a Dubai-based post-quantum, zero-key encryption infrastructure. Instead of generating a private key inside your app server, each secret splits cleanly across layers:

  • Post-quantum key encapsulation: ML-KEM-768 (NIST FIPS 203) encapsulates a fresh symmetric key, and AES-256-GCM seals the payload.
  • Zero-key threshold enclaves: When a secret is created, its private key is split immediately across a cluster of Trusted Execution Environments (TEEs). Neither your app nor any single server ever holds the full private key.
  • Public key on IPFS, ownership on-chain: Anyone can encrypt for a secret using its public key, while decryption requires authorization as the secret owner or an explicitly assigned (and revocable) delegate.
  • Bring your own storage: You keep the returned ciphertext wherever you want — Postgres, S3, a sovereign cloud in the UAE, or on-premise storage.

For the full cryptographic breakdown and comparison against classical KMS setups, see the CIFER post-quantum architecture overview.

Step 1: Install the SDK

Requires Node.js 18+:

npm install cifer-sdk 

cifer-sdk is ~23 KB gzipped and runs in both Node.js and the browser. It supports wallet signers (Web3 / EIP-1193) as well as Web2 mode (email + session auth, no wallet needed).

Step 2: Encrypt a Prompt in ~10 Lines (Web2 Mode)

Using the stateful web2.createClient() wrapper, you initialize the SDK once, open a managed session, and encrypt any payload up to 16 KB inline:

import { createCiferSdk, web2 } from 'cifer-sdk'; const sdk = await createCiferSdk({ blackboxUrl: 'https://blackbox.cifersecurity.com:3010', applicationKey: process.env.CIFER_APP_KEY!, }); const client = web2.createClient({ blackboxUrl: sdk.blackboxUrl, readClient: sdk.readClient }); await client.createManagedSession({ principalId: process.env.CIFER_PRINCIPAL_ID!, ed25519Signer }); const { secretId } = await client.createSecret(); const { cifer, encryptedMessage } = await client.payload.encryptPayload({ secretId, plaintext: 'Confidential prompt: summarize Q4 audit findings for Board review.', }); 

encryptPayload() returns two strings you can persist directly in your own database:

  • cifer: the 1104-byte ML-KEM-768 ciphertext
  • encryptedMessage: the AES-256-GCM sealed payload

Your app never touches a raw private key, and CIFER only ever sees raw bytes (it does not inspect or filter prompt contents).

Step 3: Decrypt When the Agent Needs Context

When an authorized agent session or delegate needs to reconstruct conversation history, pass secretId, cifer, and encryptedMessage back to decryptPayload():

const { decryptedMessage } = await client.payload.decryptPayload({ secretId, cifer, encryptedMessage, }); console.log(decryptedMessage); // "Confidential prompt: summarize Q4 audit findings for Board review." 

If an agent is decommissioned or compromised, you can revoke its delegation without re-encrypting or rotating a master server key.

Using Wallet-Based Auth Instead (Optional)

If you're building a Web3 or wallet-authenticated AI app, you can use blackbox.payload directly with any EIP-1193 signer:

import { createCiferSdk, Eip1193SignerAdapter, blackbox } from 'cifer-sdk'; const sdk = await createCiferSdk({ blackboxUrl: 'https://blackbox.cifersecurity.com:3010', applicationKey: process.env.CIFER_APP_KEY!, }); const signer = new Eip1193SignerAdapter(window.ethereum); const encrypted = await blackbox.payload.encryptPayload({ chainId: 8453, secretId: 123n, plaintext: 'My secret prompt', signer, readClient: sdk.readClient, blackboxUrl: sdk.blackboxUrl, }); 

Handling Larger Files (PDFs, Audio, RAG Uploads)

For documents larger than 16 KB — such as RAG attachments or compliance archives — the SDK exposes an async job API under client.files.encryptFile() / client.jobs.pollUntilComplete() so large files don't block your request loop.

Wrapping Up

Moving AI prompt and memory storage to post-quantum encryption doesn't have to mean rebuilding your entire PKI stack from scratch:

  • NIST FIPS 203 (ML-KEM-768) + AES-256-GCM out of the box
  • No private keys stored in your backend or .env files
  • Full data residency control — store ciphertext in your existing database or sovereign cloud

Check out the CIFER post-quantum technical specification or jump straight into the SDK Quick Start to try it in your own agent pipeline. (Note: cifer-sdk is currently in Beta and requires an organization applicationKey.)