Java Card Specifications · Java Card Development Kit Download · Java Card Developer Forum

Java Card post-quantum cryptography for Secure Elements, with Duke, keys, a smartphone, passport, vehicle and connected device

How do we make post-quantum cryptography practical for Secure Elements that protect identities and credentials? Supporting ML-KEM and ML-DSA is a starting point. Applications also need to provision keys, establish shared secrets, and sign or verify data within limited memory and communication capacity.

Java Card’s PQC Preview APIs give developers choices to address these constraints: compact seeds to reduce key provisioning and storage costs, reusable cryptographic instances to save resources, and options to process large messages outside the Secure Element. Java Card brings these choices into a common API, so developers can build applications for constrained devices while preserving interoperability.

The latest release of the Java Card 3.2 specifications with Preview Features defines three complementary features to address these needs: Module-Lattice-Based Keys, Key Encapsulation Mechanism (KEM), and ML-DSA digital signatures. Together, these features define a common API for creating and provisioning PQC keys, establishing shared secrets, and signing or verifying data. This supports interoperability: application developers and Secure Element implementers use the same API definitions and behavior, rather than separate vendor-specific APIs.

These APIs are Preview Features: complete for evaluation, but not yet permanent parts of the platform specification. The Java Card Development Kit Simulator implements them so developers can try them in applets today. We welcome feedback on the APIs and on how they meet application needs. To learn more, see How Preview Features Support Java Card Evolution. To get started with the Simulator, see Java Card Development Kit 26.1: Post-Quantum Cryptography and a More Interactive Development Workflow.

This article focuses on the specification and its API design: the common behavior defined for implementations, and the choices exposed to application developers.

Designing PQC APIs for Secure Elements

Secure Elements protect secrets and support identity, authentication, and confidential exchanges in many applications. Passports and automotive eSIMs can remain deployed for years. IoT equipment, such as smart meters and industrial devices, also needs long-term secure communication and remote management. Smartphone Secure Elements support services such as mobile payments, with secure application loading, updates, and management needed throughout the device's supported lifetime. These examples show why developers must prepare for cryptographic change without assuming the Secure Element can simply be replaced.

Supporting PQC now helps developers prepare these long-lived products for a time when quantum computers could recover private keys and break widely used public-key algorithms such as RSA and elliptic-curve cryptography. The enhanced Java Card specifications define the APIs that applications and implementations can use for that preparation.

Why design for post-quantum security now?

An attacker can record encrypted exchanges today and try to decrypt them later, when a sufficiently powerful quantum computer becomes available. This is the harvest now, decrypt later risk described by NIST. A later migration cannot protect exchanges already recorded under vulnerable key-establishment mechanisms.

Planning therefore depends on how long data must remain confidential, how long products will stay deployed, and how much time their migration will take. It does not require knowing the exact date when such a quantum computer will become available.

NIST IR 8547 outlines the transition from quantum-vulnerable cryptography to post-quantum standards. The Java Card Preview Features let developers start assessing that transition for their Secure Element applications.

Digital signatures raise a different concern: an attacker able to recover a signing key could impersonate a device, forge messages, or sign malicious software. Products may depend on long-lived trust anchors and verifiers that are difficult to update. Their migration also needs to be prepared before the existing protection can be broken.

How the APIs address Secure Element constraints

Java Card applications work with limited memory and communicate through APDU exchanges. PQC keys, signatures, and KEM encapsulation messages can occupy several kilobytes, affecting not just storage at rest, but also RAM use during processing and data transfers. Persistent key material may also need to remain consistent with application records across interruptions.

The APIs address these constraints through familiar Java Card concepts: key objects, persistent and transient storage, explicit algorithm configuration, reusable cryptographic instances, and transactions. Common key encodings help applications exchange keys with other systems. Defined API behavior also lets developers use the same programming model on different Secure Element implementations that support the selected features. Both contribute to interoperability.

The three features fit together as follows:

Application needPreview FeatureMain API
Create, provision, generate, expand, export, and clear keysModule-Lattice-Based Keysjavacardx.security.pqc
Establish shared key materialKEMjavacardx.crypto.kem.KEM
Sign and verify dataML-DSAjavacard.security.Signature

Module-Lattice-Based Keys: create, provision, and manage PQC keys

Before an applet can sign data or establish a shared secret, it needs to create and provision the corresponding keys. The javacardx.security.pqc package provides key objects for ML-KEM and ML-DSA, standardized in FIPS 203 and FIPS 204. Applets can generate keys within the Secure Element or import existing key material, then retrieve public keys to share. The package includes MLKEMPublicKey, MLKEMPrivateKey, MLDSAPublicKey, and MLDSAPrivateKey, together with PQCKeyFactory and EncodableKey.

Compact seeds and expanded post-quantum keys in a Secure Element

The defined ML-KEM parameter sets are ML-KEM-512, ML-KEM-768, and ML-KEM-1024; the ML-DSA sets are ML-DSA-44, ML-DSA-65, and ML-DSA-87.

The design separates creating a key object from populating its key material. This lets an applet make allocation and storage decisions before using the key.

Create only the key objects the application needs

PQCKeyFactory.buildKey(…) selects the parameter set, public or private key type, memory type, and private-key representation. During personalization, at the factory or in the field, an applet can import an ML-KEM-768 private key as a compact seed in persistent memory. Later, once the Secure Element is deployed, the applet can retrieve the corresponding public-key encoding directly from the private-key object, without creating a separate MLKEMPublicKey object.

The following example imports a 64-byte ML-KEM seed received during personalization and writes the public-key encoding into a preallocated application buffer. The applet retains only the seed key object; the public-key bytes can be sent to a service:

MLKEMPrivateKey seedKey = (MLKEMPrivateKey)
    PQCKeyFactory.buildKey(
        NamedParameterSpec.ML_KEM_768,
        (short) (KeyBuilder.ATTR_PRIVATE
            | JCSystem.MEMORY_TYPE_PERSISTENT
            | PQCKeyFactory.ATTR_SEED));

// Import the 64-byte seed received during personalization.
seedKey.setEncoded(seedBuffer, seedOffset, (short) 64);

// publicKeyBuffer has space for the 1,184-byte public key.
short publicKeyEnd = seedKey.getPublicKey(
    publicKeyBuffer, (short) 0);
// Send publicKeyEnd bytes from publicKeyBuffer, starting at offset 0.

The private key remains stored as a seed. getPublicKey(...) writes the corresponding public-key encoding into the buffer and returns the offset immediately after it. No separate public-key object or expanded private-key object is needed for this flow.

Applications can also generate new ML-KEM or ML-DSA key pairs within the Secure Element using PQCKeyFactory.generateKeyPair(publicKey, privateKey) or the existing javacard.security.KeyPair API. Both require public- and private-key destination objects created for the same parameter set. The private-key object can use either seed or expanded representation. With these objects already created, the legacy API is used as follows:

KeyPair pair = new KeyPair(publicKey, privateKey);
pair.genKeyPair();

This uses the same seed or expanded representation selected for the private-key object, with the same transaction and failure behavior as PQCKeyFactory.generateKeyPair(...).

Choose the right key representation at each lifecycle stage

During personalization, at the factory or in the field, several private keys may need to be loaded into the same Secure Element. Transferring and writing several kilobytes for each expanded key takes time and adds to personalization costs. Loading compact seeds instead reduces the data transferred and written. The expanded keys can then be generated when needed.

As shown in the following table, keeping a key in expanded form avoids repeating the expansion when performing cryptographic operations, at the cost of more storage. The application can choose the balance that suits its use case and lifecycle stage, for example provisioning seeds at the factory or in the field, then expanding and retaining frequently used keys when the application needs them.

ML-DSA and ML-KEM private keys can be represented as compact seeds or in expanded form:

RepresentationWhat is retainedApplication consideration
Seed32 bytes for ML-DSA; 64 bytes for ML-KEMSaves retained key-material space, but expansion needs computation and working memory
ExpandedThe expanded private-key encodingAvoids regenerating that representation from a seed for operations that require it

These seed lengths describe key material, not the total size of an implementation's key object.

The difference is substantial when provisioning multiple private keys during personalization. The following examples show standardized encoding sizes in bytes:

Parameter setPublic keyExpanded private keyPrivate-key seed
ML-KEM-7681,1842,40064
ML-DSA-872,5924,89632

The expanded-key sizes are specified in FIPS 203, Table 3 and FIPS 204, Table 2. With Java Card's seed representation, provisioning 10 ML-DSA-87 private keys requires 320 bytes of seed material rather than 48,960 bytes of expanded private-key encodings, excluding object overhead, public keys, and operational workspace. Applications can therefore provision private keys faster, with less data transferred from the host and less time spent writing to persistent memory, while also reducing key storage requirements.

From an initialized seed, the three-argument PQCKeyFactory.generateKeyPair(...) overload can compute the corresponding public key, expand the private key, or do both:

  • generateKeyPair(seedKey, publicKey, null): compute only the corresponding public key, for example to send it again during enrollment, while retaining the private key as a seed.
  • generateKeyPair(seedKey, null, expandedPrivateKey): expand only the private key for subsequent cryptographic operations.
  • generateKeyPair(seedKey, publicKey, expandedPrivateKey): populate both destination objects from the same seed.

These operations reproduce the keys corresponding to the existing seed, rather than generate an unrelated new pair. The input seed key remains unchanged.

An initialized MLKEMPrivateKey can also return its encoded public key through getPublicKey(...), whether the private key uses seed or expanded representation. An application does not need a separate public-key object simply to retrieve that encoding.

Common encodings and transaction-aware updates

EncodableKey.setEncoded(...) and getEncoded(...) use the primary encodings defined by FIPS 203 and FIPS 204: public and expanded private-key encodings, or the corresponding seed material.

Secure Elements can lose power or be reset at any point during an operation. For example, a contactless card can leave the reader's field while a key is being updated. In some applications, preserving a consistent key and application state through such interruptions is critical, so interruption handling is part of the API design.

The APIs retain Java Card's persistent and transient storage choices. A transaction lets the applet update a persistent key and its application data together. If the transaction is committed, both updates are kept. If it is aborted, both are undone. For example, key rotation may need to update a key and its application-level version record as one operation.

The application decides whether to use a transaction. If it can detect an incomplete operation and safely retry or recover, it can avoid the overhead and commit-capacity requirements of a transaction. When previous values must be preserved or related updates must succeed or fail together, the application can group those updates in a transaction.

Without a transaction, the outcome depends on when an interruption or failure occurs: destination keys may retain their previous values, become uninitialized, or contain fully written new values. The essential guarantee is that a key is never marked initialized with partially updated or undefined material. A transaction provides an all-or-nothing update that can preserve the previous key values if the operation fails and the transaction is aborted.

For key-pair generation, the Javadoc describes the following conceptual order:

Clear the public key
Clear the private key
Generate the new key-pair values
Set the private key to its complete new value
Set the public key to its complete new value

Each key becomes initialized when it receives its complete new value. There is no final step that initializes both keys together, so an interruption can leave the private key initialized with its new value before the public key has been updated. If generation throws an exception, it cannot leave both destination keys initialized with their new values. The caller should abort any active transaction before using the keys.

When key generation and application-state updates must succeed or fail together, an applet can group them in a transaction, conceptually as follows:

Begin transaction
Try
    Generate the key pair
    Update the application's key-version record
    Commit transaction
Catch exception
    Abort the transaction
    Propagate the exception

Plan key rotation across the whole system

Key rotation involves both the Secure Element and the systems communicating with it. For example, a device can generate a new key pair, send its public key to a service for registration or certification, and start using the new private key once the service is ready. The protocol must also define when to stop accepting the old key.

The Java Card APIs provide the building blocks for this process: applications can create, import, or generate replacement keys and retrieve their public-key encodings. When switching keys also requires updating application records, a transaction can keep those local changes consistent. The application and its protocol coordinate the transition with the other systems.

For example, a device can generate a new PQC key pair, register its public key with a service, and start using the new key once the service accepts it. The application must be able to recover if the process is interrupted. Java Card transactions can keep local key updates and application records consistent, while the application protocol coordinates the change with the service. If the change also introduces a new algorithm, the service must support it, and any affected certificates and trust stores must be updated accordingly.

KEM: establish a secret without transmitting it

Consider a service establishing shared key material with an applet. The Secure Element keeps its private key and makes the corresponding public key available to the service. The exchange works as follows:

  1. The service uses the Secure Element's public key to generate a shared secret and an encapsulation message, also called a ciphertext.
  2. The service sends the encapsulation message to the applet, not the shared secret.
  3. The applet uses its private key and that message to recover the same secret.
A Secure Element and a remote service establish a shared secret

Both sides can use the shared material to derive keys for protected communication. The same KEM model also allows an applet to encapsulate to a remote recipient. A KEM is not, by itself, an application-data encryption protocol or a complete authenticated exchange.

One programming model for classical and post-quantum KEMs

The Java Card API supports ML-KEM, standardized in FIPS 203, with the ML-KEM-512, ML-KEM-768, and ML-KEM-1024 parameter sets. It also supports classical DHKEM, defined by RFC 9180 for use in HPKE, with suites based on P-256 (secp256r1), P-384 (secp384r1), P-521 (secp521r1), X25519, and X448.

Both use the same API for encapsulation and decapsulation, allowing applications to work with classical or post-quantum KEMs through a common programming model.

Combine mechanisms through a defined hybrid protocol

A hybrid key-establishment protocol combines classical and post-quantum mechanisms to retain protection if one is later broken. For example, hybrid TLS key establishment combines classical ECDHE key agreement with ML-KEM encapsulation. A Secure Element can perform selected cryptographic operations while the host handles networking and protocol messages. Certificate-based authentication must also be considered separately.

Java Card provides the cryptographic primitives. The applet implements the protocol-specific processing, in coordination with the host or remote service, including how shared secrets are combined and keys are derived.

GlobalPlatform defines standards for managing Secure Elements and their applications. It is working on SCP12, which is expected to support post-quantum and hybrid mechanisms for operations such as key provisioning and application loading. Java Card’s KEM APIs provide relevant cryptographic building blocks, while GlobalPlatform defines the protocol and its management rules.

Configure the instance once, use it with different keys

A KEM instance is configured with its algorithm, parameter set and intended modes. The operations are stateless between calls. Each call supplies its keys and input data. There is no separate step to initialize the instance with a key before the operation. The same configured instance can process successive operations with different compatible keys.

A JCRE-owned instance that applications can share

KEM.getInstance(...) returns a permanent Entry Point Object owned by the Java Card Runtime Environment (JCRE), preallocated or allocated on request. Applets and libraries can retain and reuse its reference across contexts, reducing duplicate instances and associated resources.

Several applets can use the same KEM instance while keeping their own keys and buffers. For example, a shared service can provide an ML-KEM-768 instance to applets that communicate with different remote services. Each applet performs decapsulation in its own context, using its own private key. Because operations are stateless, the instance can be reused across these applications without retaining their individual session state.

Avoid temporary key objects and intermediate secret copies

For encapsulation, an applet can supply the recipient's public key as a key object or as encoded bytes in a buffer. The buffer form avoids creating and populating a temporary key object when a protocol delivers the peer's key for a single exchange. The encoding must match the selected KEM configuration.

Both encapsulation and decapsulation can write the shared secret to a byte array or directly into a SecretKey object, avoiding an intermediate application byte array when the next operation needs a key.

Seed expansion for ML-KEM decapsulation

An applet can expand a seed explicitly into a private-key object before decapsulation, or configure the KEM instance with MODE_EXPAND to perform expansion as part of the operation. Expanded private keys can be used directly.

With expansion during decapsulation, the application does not need to keep a separate expanded private-key object between operations. Depending on the application, this can save RAM or avoid costly writes to persistent memory. This is especially useful when many seeds are stored but only one key is used at a time. The KEM instance still needs expansion resources, which the implementation may reserve when it is created.

ML-DSA: choose where to process the message and when to expand the key

An applet can sign a challenge received from a service, which verifies the signature using the corresponding public key. ML-DSA provides post-quantum digital signatures as standardized in FIPS 204.

A Secure Element signs data for verification by another endpoint

Vehicle-to-everything communication, or V2X, illustrates another use of signatures: receivers need to verify the origin and integrity of messages exchanged by vehicles and infrastructure. Moving to post-quantum signatures also requires adapting certificate and message formats, while keeping message sizes and verification times within the system's communication and timing limits.

Java Card integrates ML-DSA into javacard.security.Signature, retaining its existing lifecycle: obtain an instance, initialize it with a key and mode, then sign or verify. Signature.OneShot offers an open/use/close lifecycle for a complete operation.

Choice one: original message or external message representative?

An applet can choose how to provide the data to sign or verify:

  • Process the message within the Secure Element. For a short authentication challenge, the applet can supply the complete message. It can also supply longer messages through successive update(...) calls. The implementation performs the hashing required by ML-DSA. An optional context of up to 255 bytes distinguishes different application purposes; verification must use the same context.
  • Prepare a large message outside the Secure Element. For a large document held outside it, another component can perform the ML-DSA message processing defined by FIPS 204 and produce the 64-byte message representative, mu. The applet passes mu to sign(...) or verify(...) rather than transferring the full message. This reduces APDU traffic and message-hashing work within the Secure Element. Any applicable context is included when mu is computed.

The external-mu mode does not accept streaming update(...) calls or a separate context during initialization.

Choice two: expanded key or seed expansion during signing?

An applet can expand a seed explicitly into a private-key object before signing, or select a Signature variant that expands it as part of the operation. The second option accepts seed or expanded private keys. Applications using only expanded keys can select a variant that does not request expansion-specific resources.

With expansion during signing, the application does not need to keep a separate expanded private-key object between signatures. Depending on the application, this can save RAM or avoid costly writes to persistent memory. This is especially useful when many seeds are stored but only one key is used at a time. An expansion-capable Signature instance reserves the necessary resources when it is obtained.

Combining the two choices gives four variants:

Constant in SignatureMessage inputPrivate-key representation for signing
SIG_CIPHER_ML_DSAOriginal messageExpanded
SIG_CIPHER_ML_DSA_EXPAND_SEEDOriginal messageSeed or expanded
SIG_CIPHER_ML_DSA_EXTERNAL_MUExternal 64-byte muExpanded
SIG_CIPHER_ML_DSA_EXTERNAL_MU_EXPAND_SEEDExternal 64-byte muSeed or expanded

Example: authenticate a device with a seed-based private key

For device authentication, an applet can use an ML-DSA-65 private key stored as a seed to sign a fresh challenge from a service. A short context such as AUTH distinguishes this use from other signing purposes. The service verifies the signature with the corresponding public key, the same challenge, and the same context.

The context and Signature object can be prepared once and reused for subsequent challenges:

Signature signer = Signature.getInstance(
    MessageDigest.ALG_NULL,
    Signature.SIG_CIPHER_ML_DSA_EXPAND_SEED,
    Cipher.PAD_NULL,
    false);

byte[] context = { 0x41, 0x55, 0x54, 0x48 }; // "AUTH"
signer.init(privateKey, Signature.MODE_SIGN,
    context, (short) 0, (short) context.length);
short signatureLength = signer.sign(
    challengeBuffer, challengeOffset, challengeLength,
    signatureBuffer, signatureOffset);

The applet returns the signature to the verifier. The seed remains in the private-key object; the selected Signature variant performs expansion for signing.

Try the Preview Features with the Java Card Development Kit Simulator

The API documentation describes the available options, and the Java Card Development Kit Simulator lets you try them: provision keys, establish a shared secret with a remote application, or sign in an applet and verify outside the Secure Element. The Simulator supports ML-KEM-512/768/1024 and ML-DSA-44/65/87. You can compare memory types, seed and expanded keys, transactional updates, and message processing. For the development workflow, including JShell and Eclipse integration, see the Java Card Development Kit 26.1: Post-Quantum Cryptography and a More Interactive Development Workflow.

Use the Simulator to test how your applet works with the rest of your application, from exchanging public keys and messages to replacing keys and recovering from interrupted updates. This helps identify integration issues early, before testing on your target Secure Element.

We welcome feedback on the Preview Features and the development experience.

Resources

Java Card Specifications · Java Card Development Kit Download · Java Card Developer Forum