KEMSpi.EncapsulatorSpi (Java SE 17 & JDK 17)
Description: declaration: module: java.base, package: javax.crypto, interface: KEMSpi, interface: EncapsulatorSpi
Keywords: javax.crypto.KEMSpi.EncapsulatorSpi interface

Module java.base
Package javax.crypto

# Interface KEMSpi.EncapsulatorSpi

Enclosing interface:
  KEMSpi

public static interface KEMSpi.EncapsulatorSpi
The KEM encapsulator implementation, generated by `KEMSpi.engineNewEncapsulator(java.security.PublicKey, java.security.spec.AlgorithmParameterSpec, java.security.SecureRandom)` on the KEM sender side.

API Note:
  This interface is defined in Java SE 17 Maintenance Release 1.
Since:
  17
See Also:
  - `KEM.Encapsulator`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `KEM.Encapsulated`
  `engineEncapsulate(int from, int to, String algorithm)`
  The key encapsulation function.
  `int`
  `engineEncapsulationSize()`
  Returns the size of the key encapsulation message.
  `int`
  `engineSecretSize()`
  Returns the size of the shared secret.

- ## Method Details

  - ### engineEncapsulate

    KEM.Encapsulated engineEncapsulate(int from, int to, String algorithm)
    The key encapsulation function.

    Each invocation of this method must generate a new secret key and key encapsulation message that is returned in an `KEM.Encapsulated` object.

    An implementation must support the case where `from` is 0, `to` is the same as the return value of `secretSize()`, and `algorithm` is "Generic".

    Parameters:
      `from` - the initial index of the shared secret byte array to be returned, inclusive
      `to` - the final index of the shared secret byte array to be returned, exclusive
      `algorithm` - the algorithm name for the secret key that is returned
    Returns:
      an `KEM.Encapsulated` object containing a portion of the shared secret as a key with the specified algorithm, key encapsulation message, and optional parameters.
    Throws:
      `IndexOutOfBoundsException` - if `from < 0`, `from > to`, or `to > secretSize()`
      `NullPointerException` - if `algorithm` is `null`
      `UnsupportedOperationException` - if the combination of `from`, `to`, and `algorithm` is not supported by the encapsulator
    See Also:
      - `KEM.Encapsulated`
      - `KEM.Encapsulator.encapsulate(int, int, String)`

  - ### engineSecretSize

    int engineSecretSize()
    Returns the size of the shared secret.
    Returns:
      the size of the shared secret as a finite non-negative integer
    See Also:
      - `KEM.Encapsulator.secretSize()`

  - ### engineEncapsulationSize

    int engineEncapsulationSize()
    Returns the size of the key encapsulation message.
    Returns:
      the size of the key encapsulation message as a finite non-negative integer
    See Also:
      - `KEM.Encapsulator.encapsulationSize()`