Package org.conscrypt

Class 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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getEncapsulated()
      Returns the encapsulated key created for this HpkeContextSender.
      static HpkeContextSender getInstance​(java.lang.String suite)
      Returns an uninitialised HpkeContextSender.
      static HpkeContextSender getInstance​(java.lang.String suite, java.lang.String providerName)
      Returns an uninitialised HpkeContextSender from a specific Provider
      static HpkeContextSender getInstance​(java.lang.String suite, java.security.Provider provider)
      Returns an uninitialised HpkeContextSender from a specific Provider
      void init​(java.security.PublicKey recipientKey, byte[] info)
      Initialises this HpkeContextSender in BASE mode, i.e.
      void init​(java.security.PublicKey recipientKey, byte[] info, byte[] psk, byte[] psk_id)
      Initialises this HpkeContextSender in PSK mode, i.e.
      void init​(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey)
      Initialises this HpkeContextSender in AUTH mode, i.e.
      void init​(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey, byte[] psk, byte[] psk_id)
      Initialises this HpkeContextSender in PSK_AUTH mode, i.e.
      void initForTesting​(java.security.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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HpkeContextSender

        private HpkeContextSender​(HpkeSpi spi)
    • Method Detail

      • getEncapsulated

        public byte[] getEncapsulated()
        Returns the encapsulated key created for this HpkeContextSender.
        Returns:
        the encapsulated key
        Throws:
        java.lang.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:
        java.lang.NullPointerException - if the plaintext is null
        java.lang.IllegalStateException - if this HpkeContextSender has not been initialised
      • getInstance

        public static HpkeContextSender getInstance​(java.lang.String suite)
                                             throws java.security.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:
        java.security.NoSuchAlgorithmException - if no implementation could be found
      • getInstance

        public static HpkeContextSender getInstance​(java.lang.String suite,
                                                    java.lang.String providerName)
                                             throws java.security.NoSuchAlgorithmException,
                                                    java.security.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:
        java.security.NoSuchAlgorithmException - if no implementation could be found
        java.security.NoSuchProviderException - if providerName is null or no such Provider exists
      • getInstance

        public static HpkeContextSender getInstance​(java.lang.String suite,
                                                    java.security.Provider provider)
                                             throws java.security.NoSuchAlgorithmException,
                                                    java.security.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:
        java.security.NoSuchAlgorithmException - if no implementation could be found
        java.security.NoSuchProviderException - if provider is null
      • init

        public void init​(java.security.PublicKey recipientKey,
                         byte[] info)
                  throws java.security.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:
        java.security.InvalidKeyException - if recipientKey is null or an unsupported key format
        java.lang.UnsupportedOperationException - if mode is not a supported HPKE mode
        java.lang.IllegalStateException - if this HpkeContextSender has already been initialised
      • init

        public void init​(java.security.PublicKey recipientKey,
                         byte[] info,
                         java.security.PrivateKey senderKey)
                  throws java.security.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:
        java.security.InvalidKeyException - if either recipientKey or senderKey are null or an unsupported key format
        java.lang.UnsupportedOperationException - if mode is not a supported HPKE mode
        java.lang.IllegalStateException - if this HpkeContextSender has already been initialised
      • init

        public void init​(java.security.PublicKey recipientKey,
                         byte[] info,
                         byte[] psk,
                         byte[] psk_id)
                  throws java.security.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:
        java.lang.NullPointerException - if psk or psk_id are null
        java.security.InvalidKeyException - if recipientKey is null or an unsupported key format
        java.lang.UnsupportedOperationException - if mode is not a supported HPKE mode
        java.lang.IllegalStateException - if this HpkeContextSender has already been initialised
      • init

        public void init​(java.security.PublicKey recipientKey,
                         byte[] info,
                         java.security.PrivateKey senderKey,
                         byte[] psk,
                         byte[] psk_id)
                  throws java.security.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:
        java.lang.NullPointerException - if psk or psk_id are null
        java.security.InvalidKeyException - if either recipientKey or senderKey are null or an unsupported key format
        java.lang.UnsupportedOperationException - if mode is not a supported HPKE mode
        java.lang.IllegalStateException - if this HpkeContextSender has already been initialised
      • initForTesting

        @Internal
        public void initForTesting​(java.security.PublicKey recipientKey,
                                   byte[] info,
                                   byte[] sKe)
                            throws java.security.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:
        java.security.InvalidKeyException - if recipientKey is null or an unsupported key format
        java.lang.UnsupportedOperationException - if mode is not a supported HPKE mode
        java.lang.IllegalStateException - if this HpkeContextSender has already been initialised
        java.lang.IllegalArgumentException - if sKe is null