The getInstance method creates a new KEM object that
implements the specified algorithm.
A KEM object is immutable. It is safe to call multiple
newEncapsulator and newDecapsulator methods on the
same KEM object at the same time.
If a provider is not specified in the getInstance method when
instantiating a KEM object, the newEncapsulator and
newDecapsulator methods may return encapsulators or decapsulators
from different providers. The provider selected is based on the parameters
passed to the newEncapsulator or newDecapsulator methods:
the private or public key and the optional AlgorithmParameterSpec.
The Encapsulator#providerName and Decapsulator#providerName
methods return the name of the selected provider.
Encapsulator and Decapsulator objects are also immutable.
It is safe to invoke multiple encapsulate and decapsulate
methods on the same Encapsulator or Decapsulator object
at the same time. Each invocation of encapsulate will generate a
new shared secret and key encapsulation message.
Example operation using a fictitious KEM algorithm ABC:
// Receiver side KeyPairGenerator g = KeyPairGenerator.getInstance("ABC"); KeyPair kp = g.generateKeyPair(); publishKey(kp.getPublic()); // Sender side KEM senderKEM = KEM.getInstance("ABC"); PublicKey receiverPublicKey = retrieveKey(); ABCKEMParameterSpec senderSpec = new ABCKEMParameterSpec(args); KEM.Encapsulator e = senderKEM.newEncapsulator( receiverPublicKey, senderSpec, null); KEM.Encapsulated enc = e.encapsulate(); SecretKey senderSecret = enc.key(); sendBytes(enc.encapsulation()); sendBytes(enc.params()); // Receiver side byte[] ciphertext = receiveBytes(); byte[] params = receiveBytes(); KEM receiverKEM = KEM.getInstance("ABC"); AlgorithmParameters algParams = AlgorithmParameters.getInstance("ABC"); algParams.init(params); ABCKEMParameterSpec receiverSpec = algParams.getParameterSpec(ABCKEMParameterSpec.class); KEM.Decapsulator d = receiverKEM.newDecapsulator(kp.getPrivate(), receiverSpec); SecretKey receiverSecret = d.decapsulate(ciphertext); // senderSecret and receiverSecret should now be equal.
| Modifier and Type | Class and Description |
|---|---|
| public static class | KEM.
A decapsulator, generated by |
| private static class | |
| public static class | KEM.
This class specifies the return value of the encapsulate method of
a Key Encapsulation Mechanism (KEM), which includes the shared secret
(as a |
| public static class | KEM.
An encapsulator, generated by |
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private final KEM. | |
| private final Provider | |
| private final KEMSpi |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the name of the algorithm for thisKEM object.Returns the name of the algorithm for this |
| public static KEM | Returns: the newKEM objectthe name of the KEM algorithm.
See the algorithm)KEM section in the
Java Security Standard Algorithm Names Specification
for information about standard KEM algorithm names.Returns a |
| public static KEM | Returns: the newKEM objectthe name of the KEM algorithm.
See the algorithm, Provider KEM section in the
Java Security Standard Algorithm Names Specification
for information about standard KEM algorithm names.the provider. If provider)null, this method is equivalent
to getInstance(String).Returns a |
| public static KEM | Returns: the newKEM objectthe name of the KEM algorithm.
See the algorithm, String KEM section in the
Java Security Standard Algorithm Names Specification
for information about standard KEM algorithm names.the provider. If provider)null, this method is equivalent
to getInstance(String).Returns a |
| public KEM. | Returns: the decapsulator for this keythe receiver's private key, must not be privateKey)nullCreates a KEM decapsulator on the KEM receiver side. |
| public KEM. | Returns: the decapsulator for this keythe receiver's private key, must not be privateKey, AlgorithmParameterSpec nullthe parameter, can be spec)nullCreates a KEM decapsulator on the KEM receiver side. |
| public KEM. | Returns: the encapsulator for this keythe receiver's public key, must not be publicKey)nullCreates a KEM encapsulator on the KEM sender side. |
| public KEM. | Returns: the encapsulator for this keythe receiver's public key, must not be publicKey, SecureRandom nullthe source of randomness for encapsulation.
If secureRandom) null, a default one from the
implementation will be used.Creates a KEM encapsulator on the KEM sender side. |
| public KEM. | Returns: the encapsulator for this keythe receiver's public key, must not be publicKey, AlgorithmParameterSpec nullthe optional parameter, can be spec, SecureRandom nullthe source of randomness for encapsulation.
If secureRandom) null, a default one from the
implementation will be used.Creates a KEM encapsulator on the KEM sender side. |
| algorithm | back to summary |
|---|---|
| private final String algorithm | |
| delayed | back to summary |
|---|---|
| private final KEM. | |
| provider | back to summary |
|---|---|
| private final Provider provider | |
| spi | back to summary |
|---|---|
| private final KEMSpi spi | |
| KEM | back to summary |
|---|---|
| private KEM(String algorithm, KEMSpi spi, Provider provider) | |
| KEM | back to summary |
|---|---|
| private KEM(String algorithm, KEM. | |
| getAlgorithm | back to summary |
|---|---|
| public String getAlgorithm() Returns the name of the algorithm for this
| |
| getInstance | back to summary |
|---|---|
| public static KEM getInstance(String algorithm) throws NoSuchAlgorithmException Returns a
| |
| getInstance | back to summary |
|---|---|
| public static KEM getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException Returns a
| |
| getInstance | back to summary |
|---|---|
| public static KEM getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException Returns a
| |
| newDecapsulator | back to summary |
|---|---|
| public KEM. Creates a KEM decapsulator on the KEM receiver side.
This method is equivalent to
| |
| newDecapsulator | back to summary |
|---|---|
| public KEM. Creates a KEM decapsulator on the KEM receiver side.
| |
| newEncapsulator | back to summary |
|---|---|
| public KEM. Creates a KEM encapsulator on the KEM sender side.
This method is equivalent to
| |
| newEncapsulator | back to summary |
|---|---|
| public KEM. Creates a KEM encapsulator on the KEM sender side.
This method is equivalent to
| |
| newEncapsulator | back to summary |
|---|---|
| public KEM. Creates a KEM encapsulator on the KEM sender side.
An algorithm can define an
| |
newDecapsulator on the KEM
receiver side.
This class represents the key decapsulation function of a KEM.
An invocation of the decapsulate method recovers the
secret key from the key encapsulation message.
| Modifier and Type | Field and Description |
|---|---|
| private final KEMSpi. | |
| private final Provider |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public SecretKey | Returns: the shared secret as aSecretKey with
an algorithm name of "Generic"the key encapsulation message from the sender.
The size must be equal to the value returned by
encapsulation)encapsulationSize(), or a DecapsulateException
will be thrown.The key decapsulation function. |
| public SecretKey | Returns: a portion of the shared secret as aSecretKey
containing the bytes of the secret ranging from from
to to, exclusive, and an algorithm name as specified.
For example, decapsulate(encapsulation, secretSize()
- 16, secretSize(), "AES") uses the last 16 bytes
of the shared secret as a 128-bit AES key.the key encapsulation message from the sender.
The size must be equal to the value returned by
encapsulation, int encapsulationSize(), or a DecapsulateException
will be thrown.the initial index of the shared secret byte array
to be returned, inclusive from, int the final index of the shared secret byte array
to be returned, exclusive to, String the algorithm name for the secret key that is returned.
See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names.
Specify "Generic" if the output will be used as the input keying
material of a key derivation function (KDF). algorithm)The key decapsulation function. |
| public int | Returns: the size of the key encapsulation messageReturns the size of the key encapsulation message. |
| public String | |
| public int |
| d | back to summary |
|---|---|
| private final KEMSpi. | |
| p | back to summary |
|---|---|
| private final Provider p | |
| Decapsulator | back to summary |
|---|---|
| private Decapsulator(KEMSpi. | |
| decapsulate | back to summary |
|---|---|
| public SecretKey decapsulate(byte[] encapsulation) throws DecapsulateException The key decapsulation function.
This method is equivalent to
The generated secret key is usually passed to a key derivation function (KDF) as the input keying material.
| |
| decapsulate | back to summary |
|---|---|
| public SecretKey decapsulate(byte[] encapsulation, int from, int to, String algorithm) throws DecapsulateException The key decapsulation function. An invocation of this method recovers the secret key from the key encapsulation message.
An implementation may choose to not support arbitrary combinations
of
| |
| encapsulationSize | back to summary |
|---|---|
| public int encapsulationSize() Returns the size of the key encapsulation message. This method can be used to extract the encapsulation message from a longer byte array if no length information is provided by a higher level protocol.
| |
| providerName | back to summary |
|---|---|
| public String providerName() Returns the name of the provider.
| |
| secretSize | back to summary |
|---|---|
| public int secretSize() Returns the size of the shared secret.
This method can be called to find out the length of the shared secret
before
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static <T extends Exception> T | |
| private KEM. | |
| private KEM. |
| list | back to summary |
|---|---|
| private final Provider. | |
| DelayedKEM | back to summary |
|---|---|
| private DelayedKEM(Provider. | |
| merge | back to summary |
|---|---|
| private static <T extends Exception> T merge(T e1, T e2) | |
| newDecapsulator | back to summary |
|---|---|
| private KEM. | |
| newEncapsulator | back to summary |
|---|---|
| private KEM. | |
SecretKey), the key encapsulation message,
and optional parameters.Note
the key encapsulation message can be also referred to as ciphertext.
newEncapsulator(PublicKey, AlgorithmParameterSpec, SecureRandom), Encapsulator#encapsulate(int, int, String)
| Modifier and Type | Field and Description |
|---|---|
| private final byte[] | |
| private final SecretKey | |
| private final byte[] |
| Access | Constructor and Description |
|---|---|
| public | Encapsulated(SecretKey
the shared secret as a key, must not be key, byte[] null.the key encapsulation message, must not
be encapsulation, byte[] null. The contents of the array are copied
to protect against subsequent modification.optional parameters, can be params)null.
The contents of the array are copied to protect
against subsequent modification.Constructs an |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | Returns: the key encapsulation message. A new copy of the byte array is returned.Returns the key encapsulation message. |
| public SecretKey | |
| public byte[] | Returns: the optional parameters in a byte array ornull
if not specified. A new copy of the byte array is returned.Returns the optional parameters in a byte array. |
| encapsulation | back to summary |
|---|---|
| private final byte[] encapsulation | |
| key | back to summary |
|---|---|
| private final SecretKey key | |
| params | back to summary |
|---|---|
| private final byte[] params | |
| Encapsulated | back to summary |
|---|---|
| public Encapsulated(SecretKey key, byte[] encapsulation, byte[] params) Constructs an
| |
| encapsulation | back to summary |
|---|---|
| public byte[] encapsulation() Returns the key encapsulation message.
| |
| key | back to summary |
|---|---|
| public SecretKey key() Returns the
| |
| params | back to summary |
|---|---|
| public byte[] params() Returns the optional parameters in a byte array.
| |
newEncapsulator on the KEM
sender side.
This class represents the key encapsulation function of a KEM.
Each invocation of the encapsulate method generates a
new secret key and key encapsulation message that is returned
in an Encapsulated object.
| Modifier and Type | Field and Description |
|---|---|
| private final KEMSpi. | |
| private final Provider |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public KEM. | Returns: aEncapsulated object containing the shared
secret, key encapsulation message, and optional parameters.
The shared secret is a SecretKey containing all of
the bytes of the secret, and an algorithm name of "Generic".The key encapsulation function. |
| public KEM. | Returns: aEncapsulated object containing a portion of
the shared secret, key encapsulation message, and optional
parameters. The portion of the shared secret is a
SecretKey containing the bytes of the secret
ranging from from to to, exclusive,
and an algorithm name as specified. For example,
encapsulate(0, 16, "AES") uses the first 16 bytes
of the shared secret as a 128-bit AES key.the initial index of the shared secret byte array
to be returned, inclusive from, int the final index of the shared secret byte array
to be returned, exclusive to, String the algorithm name for the secret key that is returned.
See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names.
Specify "Generic" if the output will be used as the input keying
material of a key derivation function (KDF). algorithm)The key encapsulation function. |
| public int | Returns: the size of the key encapsulation messageReturns the size of the key encapsulation message. |
| public String | |
| public int |
| e | back to summary |
|---|---|
| private final KEMSpi. | |
| p | back to summary |
|---|---|
| private final Provider p | |
| Encapsulator | back to summary |
|---|---|
| private Encapsulator(KEMSpi. | |
| encapsulate | back to summary |
|---|---|
| public KEM. The key encapsulation function.
This method is equivalent to
The generated secret key is usually passed to a key derivation function (KDF) as the input keying material.
| |
| encapsulate | back to summary |
|---|---|
| public KEM. The key encapsulation function.
Each invocation of this method generates a new secret key and key
encapsulation message that is returned in an
An implementation may choose to not support arbitrary combinations
of
| |
| encapsulationSize | back to summary |
|---|---|
| public int encapsulationSize() Returns the size of the key encapsulation message.
This method can be called to find out the length of the encapsulation
message before
| |
| providerName | back to summary |
|---|---|
| public String providerName() Returns the name of the provider.
| |
| secretSize | back to summary |
|---|---|
| public int secretSize() Returns the size of the shared secret.
This method can be called to find out the length of the shared secret
before
| |