Package org.conscrypt

Class HpkeContextRecipient


  • public class HpkeContextRecipient
    extends HpkeContext
    Hybrid Public Key Encryption (HPKE) recipient APIs.
    See Also:
    HPKE RFC 9180 Recipient subclass of HpkeContext. See base class for details.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static HpkeContextRecipient getInstance​(java.lang.String suite)
      Returns an uninitialised HpkeContextRecipient.
      static HpkeContextRecipient getInstance​(java.lang.String suite, java.lang.String providerName)
      Returns an uninitialised HpkeContextRecipient from a specific Provider
      static HpkeContextRecipient getInstance​(java.lang.String suite, java.security.Provider provider)
      Returns an uninitialised HpkeContextRecipient from a specific Provider
      void init​(byte[] encapsulated, java.security.PrivateKey recipientKey, byte[] info)
      Initialises this HpkeContextRecipient in BASE mode, i.e.
      void init​(byte[] encapsulated, java.security.PrivateKey recipientKey, byte[] info, byte[] psk, byte[] psk_id)
      Initialises this HpkeContextRecipient in PSK_AUTH mode, i.e.
      void init​(byte[] encapsulated, java.security.PrivateKey recipientKey, byte[] info, java.security.PublicKey senderKey)
      Initialises this HpkeContextRecipient in AUTH mode, i.e.
      void init​(byte[] encapsulated, java.security.PrivateKey recipientKey, byte[] info, java.security.PublicKey senderKey, byte[] psk, byte[] psk_id)
      Initialises this HpkeContextRecipient in PSK_AUTH mode, i.e.
      byte[] open​(byte[] ciphertext, byte[] aad)
      Opens a message, using the internal key schedule maintained by this HpkeContextRecipient.
      • Methods inherited from class java.lang.Object

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

      • HpkeContextRecipient

        private HpkeContextRecipient​(HpkeSpi spi)
    • Method Detail

      • open

        public byte[] open​(byte[] ciphertext,
                           byte[] aad)
                    throws java.security.GeneralSecurityException
        Opens a message, using the internal key schedule maintained by this HpkeContextRecipient.
        Parameters:
        ciphertext - the ciphertext
        aad - optional associated data, may be null or empty
        Returns:
        the plaintext
        Throws:
        java.lang.IllegalStateException - if this HpkeContextRecipient has not been initialised
        java.security.GeneralSecurityException - on decryption failures
      • getInstance

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

        public static HpkeContextRecipient getInstance​(java.lang.String suite,
                                                       java.lang.String providerName)
                                                throws java.security.NoSuchAlgorithmException,
                                                       java.security.NoSuchProviderException
        Returns an uninitialised HpkeContextRecipient 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 HpkeContextRecipient 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 HpkeContextRecipient getInstance​(java.lang.String suite,
                                                       java.security.Provider provider)
                                                throws java.security.NoSuchAlgorithmException,
                                                       java.security.NoSuchProviderException
        Returns an uninitialised HpkeContextRecipient from a specific Provider
        Parameters:
        suite - the HPKE suite to use. @see HpkeSuite for details.
        provider - the Provider to use
        Returns:
        an uninitialised HpkeContextRecipient 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
      • init

        public void init​(byte[] encapsulated,
                         java.security.PrivateKey recipientKey,
                         byte[] info)
                  throws java.security.InvalidKeyException
        Initialises this HpkeContextRecipient in BASE mode, i.e. no sender authentication.
        Parameters:
        encapsulated - encapsulated ephemeral key from an HpkeContextSender
        recipientKey - private key of the recipient
        info - 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 HpkeContextRecipient has already been initialised
      • init

        public void init​(byte[] encapsulated,
                         java.security.PrivateKey recipientKey,
                         byte[] info,
                         java.security.PublicKey senderKey)
                  throws java.security.InvalidKeyException
        Initialises this HpkeContextRecipient in AUTH mode, i.e. messages are authenticated using the sender's public key.
        Parameters:
        encapsulated - encapsulated ephemeral key from an HpkeContextSender
        recipientKey - private key of the recipient
        info - application-supplied information, may be null or empty
        senderKey - the public 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 HpkeContextRecipient has already been initialised
      • init

        public void init​(byte[] encapsulated,
                         java.security.PrivateKey recipientKey,
                         byte[] info,
                         byte[] psk,
                         byte[] psk_id)
                  throws java.security.InvalidKeyException
        Initialises this HpkeContextRecipient in PSK_AUTH mode, i.e. messages are authenticated using a pre-shared secret key.
        Parameters:
        encapsulated - encapsulated ephemeral key from an HpkeContextSender
        recipientKey - private key of the recipient
        info - 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 HpkeContextRecipient has already been initialised
      • init

        public void init​(byte[] encapsulated,
                         java.security.PrivateKey recipientKey,
                         byte[] info,
                         java.security.PublicKey senderKey,
                         byte[] psk,
                         byte[] psk_id)
                  throws java.security.InvalidKeyException
        Initialises this HpkeContextRecipient in PSK_AUTH mode, i.e. messages are authenticated using both the sender's public key and a pre-shared secret key.
        Parameters:
        encapsulated - encapsulated ephemeral key from an HpkeContextSender
        recipientKey - private key of the recipient
        info - application-supplied information, may be null or empty
        senderKey - the public 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 HpkeContextRecipient has already been initialised