Class KeyEncapsulationExchange
java.lang.Object
net.jrodolfo.java_evolution.java21.key_encapsulation.KeyEncapsulationExchange
Demonstrates the full Java 21 Key Encapsulation Mechanism API flow.
The example models a receiver, often called Bob, that owns a public/private key pair. A sender, often called Alice, uses Bob's public key to create a shared secret and an encapsulation message. Bob then uses his private key and the encapsulation message to recover the same shared secret.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCaptures the observable result of the KEM exchange for tests and readers. -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
KeyEncapsulationExchange
public KeyEncapsulationExchange()
-
-
Method Details
-
exchange
public KeyEncapsulationExchange.KeyExchangeResult exchange() throws NoSuchAlgorithmException, InvalidKeyException, DecapsulateExceptionRuns a complete in-memory KEM exchange.- Returns:
- the sender and receiver secrets plus the encapsulation message
- Throws:
NoSuchAlgorithmException- if X25519 or DHKEM is not availableInvalidKeyException- if the generated keys cannot be used for DHKEMDecapsulateException- if the encapsulation cannot be decoded by the receiver
-