Package org.conscrypt

Class HpkeContextSender

java.lang.Object
org.conscrypt.HpkeContext
org.conscrypt.HpkeContextSender

public class HpkeContextSender extends HpkeContext
Hybrid Public Key Encryption (HPKE) sender APIs.
See Also:
  • HPKE RFC 9180 Sender subclass of HpkeContext. See base class for details.
  • Field Summary

    Fields inherited from class org.conscrypt.HpkeContext

    spi
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the encapsulated key created for this HpkeContextSender.
    Returns an uninitialised HpkeContextSender.
    getInstance(String suite, String providerName)
    Returns an uninitialised HpkeContextSender from a specific Provider
    getInstance(String suite, Provider provider)
    Returns an uninitialised HpkeContextSender from a specific Provider
    void
    init(PublicKey recipientKey, byte[] info)
    Initialises this HpkeContextSender in BASE mode, i.e. with no sender authentication.
    void
    init(PublicKey recipientKey, byte[] info, byte[] psk, byte[] psk_id)
    Initialises this HpkeContextSender in PSK mode, i.e. messages are authenticated using a pre-shared secret key.
    void
    init(PublicKey recipientKey, byte[] info, PrivateKey senderKey)
    Initialises this HpkeContextSender in AUTH mode, i.e. messages are authenticated using the sender's public key.
    void
    init(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id)
    Initialises this HpkeContextSender in PSK_AUTH mode, i.e. messages are authenticated using both the sender's public key and a pre-shared secret key.
    void
    initForTesting(PublicKey recipientKey, byte[] info, byte[] sKe)
    Initialises this HpkeContextSender for testing in BASE mode ONLY.
    byte[]
    seal(byte[] plaintext, byte[] aad)
    Seals a message, using the internal key schedule maintained by this HpkeContextSender.

    Methods inherited from class org.conscrypt.HpkeContext

    export, findSpi, findSpi, findSpi, getSpi

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getEncapsulated

      public byte[] getEncapsulated()
      Returns the encapsulated key created for this HpkeContextSender.
      Returns:
      the encapsulated key
      Throws:
      IllegalStateException - if this HpkeContextSender has not been initialised.
    • seal

      public byte[] seal(byte[] plaintext, byte[] aad)
      Seals a message, using the internal key schedule maintained by this HpkeContextSender.
      Parameters:
      plaintext - the plaintext
      aad - optional associated data, may be null or empty
      Returns:
      the ciphertext
      Throws:
      NullPointerException - if the plaintext is null
      IllegalStateException - if this HpkeContextSender has not been initialised
    • getInstance

      public static HpkeContextSender getInstance(String suite) throws NoSuchAlgorithmException
      Returns an uninitialised HpkeContextSender.
      Parameters:
      suite - the HPKE suite to use. @see HpkeSuite for details.
      Returns:
      an uninitialised HpkeContextSender for the requested suite
      Throws:
      NoSuchAlgorithmException - if no implementation could be found
    • getInstance

      public static HpkeContextSender getInstance(String suite, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException
      Returns an uninitialised HpkeContextSender from a specific Provider
      Parameters:
      suite - the HPKE suite to use. @see HpkeSuite for details.
      providerName - the name of the Provider to use
      Returns:
      an uninitialised HpkeContextSender for the requested suite
      Throws:
      NoSuchAlgorithmException - if no implementation could be found
      NoSuchProviderException - if providerName is null or no such Provider exists
    • getInstance

      public static HpkeContextSender getInstance(String suite, Provider provider) throws NoSuchAlgorithmException, NoSuchProviderException
      Returns an uninitialised HpkeContextSender from a specific Provider
      Parameters:
      suite - the HPKE suite to use. @see HpkeSuite for details.
      provider - the Provider to use
      Returns:
      an uninitialised HpkeContextSender for the requested suite
      Throws:
      NoSuchAlgorithmException - if no implementation could be found
      NoSuchProviderException - if provider is null
    • init

      public void init(PublicKey recipientKey, byte[] info) throws InvalidKeyException
      Initialises this HpkeContextSender in BASE mode, i.e. with no sender authentication.
      Parameters:
      recipientKey - public key of the recipient
      info - additional application-supplied information, may be null or empty
      Throws:
      InvalidKeyException - if recipientKey is null or an unsupported key format
      UnsupportedOperationException - if mode is not a supported HPKE mode
      IllegalStateException - if this HpkeContextSender has already been initialised
    • init

      public void init(PublicKey recipientKey, byte[] info, PrivateKey senderKey) throws InvalidKeyException
      Initialises this HpkeContextSender in AUTH mode, i.e. messages are authenticated using the sender's public key.
      Parameters:
      recipientKey - public key of the recipient
      info - additional application-supplied information, may be null or empty
      senderKey - private key of the sender
      Throws:
      InvalidKeyException - if either recipientKey or senderKey are null or an unsupported key format
      UnsupportedOperationException - if mode is not a supported HPKE mode
      IllegalStateException - if this HpkeContextSender has already been initialised
    • init

      public void init(PublicKey recipientKey, byte[] info, byte[] psk, byte[] psk_id) throws InvalidKeyException
      Initialises this HpkeContextSender in PSK mode, i.e. messages are authenticated using a pre-shared secret key.
      Parameters:
      recipientKey - public key of the recipient
      info - additional application-supplied information, may be null or empty
      psk - the a pre-shared secret key
      psk_id - the id of the pre-shared secret key
      Throws:
      NullPointerException - if psk or psk_id are null
      InvalidKeyException - if recipientKey is null or an unsupported key format
      UnsupportedOperationException - if mode is not a supported HPKE mode
      IllegalStateException - if this HpkeContextSender has already been initialised
    • init

      public void init(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id) throws InvalidKeyException
      Initialises this HpkeContextSender in PSK_AUTH mode, i.e. messages are authenticated using both the sender's public key and a pre-shared secret key.
      Parameters:
      recipientKey - public key of the recipient
      info - additional application-supplied information, may be null or empty
      senderKey - private key of the sender
      psk - the a pre-shared secret key
      psk_id - the id of the pre-shared secret key
      Throws:
      NullPointerException - if psk or psk_id are null
      InvalidKeyException - if either recipientKey or senderKey are null or an unsupported key format
      UnsupportedOperationException - if mode is not a supported HPKE mode
      IllegalStateException - if this HpkeContextSender has already been initialised
    • initForTesting

      @Internal public void initForTesting(PublicKey recipientKey, byte[] info, byte[] sKe) throws InvalidKeyException
      Initialises this HpkeContextSender for testing in BASE mode ONLY.
      Parameters:
      recipientKey - public key of the recipient
      info - additional application-supplied information, may be null or empty
      sKe - random seed to use during testing
      Throws:
      InvalidKeyException - if recipientKey is null or an unsupported key format
      UnsupportedOperationException - if mode is not a supported HPKE mode
      IllegalStateException - if this HpkeContextSender has already been initialised
      IllegalArgumentException - if sKe is null