This quickstart walks you through everything needed to perform your first post-quantum encryption withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ecies/js-post-quantum/llms.txt
Use this file to discover all available pages before exploring further.
@ecies/post-quantum — from installation to generating a key pair, encrypting data, and decrypting it back to plaintext. All examples use the library’s defaults: ML-KEM-768 for key encapsulation and AES-256-GCM for symmetric encryption.
Install the package
Install For pnpm, yarn, bun, and platform-specific setup (Deno, React Native, browser), see the Installation guide.
@ecies/post-quantum from the npm registry:npm
Generate a key pair
Key pairs are generated through the The public key is shared with anyone who needs to encrypt messages to you. Keep the secret key private — it is the only thing that can decrypt messages encrypted to the corresponding public key.
asymmetricModule exposed by DEFAULT_CONFIG. The keygen() method returns a secretKey and a publicKey as raw Uint8Array buffers.Encrypt data
Call
encrypt(publicKey, data) with the receiver’s public key and your plaintext as a Uint8Array. It returns a single Uint8Array that bundles the ML-KEM ciphertext, nonce, AEAD authentication tag, and encrypted payload:Both
encrypt and decrypt operate on Uint8Array. Convert strings with TextEncoder / TextDecoder, or use Buffer.from(str) / Buffer.toString() in Node.js. Do not pass raw strings directly.Decrypt data
Call If the ciphertext has been tampered with, the underlying AEAD cipher will throw an authentication error before returning any data.
decrypt(secretKey, encryptedData) with the receiver’s secret key and the full encrypted payload returned by encrypt. It returns the original plaintext as a Uint8Array.Full working example
The following self-contained example mirrors the canonical usage inexample/runtime/main.js:
DEFAULT_CONFIG uses ML-KEM-768 for key encapsulation and AES-256-GCM with a 16-byte nonce for symmetric encryption. This is the NIST-recommended configuration and a sensible default for most applications.
Next steps
Configuration
Learn how to switch between ML-KEM variants and symmetric ciphers by constructing a custom
Config object.API Reference
Full reference for
encrypt, decrypt, Config, and DEFAULT_CONFIG, including all parameter types and return values.