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
-
-
Constructor Summary
Constructors Modifier Constructor Description privateHpkeContextSender(HpkeSpi spi)
-
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 HpkeContextSendergetInstance(java.lang.String suite)Returns an uninitialised HpkeContextSender.static HpkeContextSendergetInstance(java.lang.String suite, java.lang.String providerName)Returns an uninitialised HpkeContextSender from a specificProviderstatic HpkeContextSendergetInstance(java.lang.String suite, java.security.Provider provider)Returns an uninitialised HpkeContextSender from a specificProvidervoidinit(java.security.PublicKey recipientKey, byte[] info)Initialises this HpkeContextSender in BASE mode, i.e.voidinit(java.security.PublicKey recipientKey, byte[] info, byte[] psk, byte[] psk_id)Initialises this HpkeContextSender in PSK mode, i.e.voidinit(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey)Initialises this HpkeContextSender in AUTH mode, i.e.voidinit(java.security.PublicKey recipientKey, byte[] info, java.security.PrivateKey senderKey, byte[] psk, byte[] psk_id)Initialises this HpkeContextSender in PSK_AUTH mode, i.e.voidinitForTesting(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.
-
-
-
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 plaintextaad- optional associated data, may be null or empty- Returns:
- the ciphertext
- Throws:
java.lang.NullPointerException- if the plaintext is nulljava.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. @seeHpkeSuitefor 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 specificProvider- Parameters:
suite- the HPKE suite to use. @seeHpkeSuitefor 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 foundjava.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 specificProvider- Parameters:
suite- the HPKE suite to use. @seeHpkeSuitefor details.provider- the Provider to use- Returns:
- an uninitialised HpkeContextSender for the requested suite
- Throws:
java.security.NoSuchAlgorithmException- if no implementation could be foundjava.security.NoSuchProviderException- if provider is null
-
init
public void init(java.security.PublicKey recipientKey, byte[] info) throws java.security.InvalidKeyExceptionInitialises this HpkeContextSender in BASE mode, i.e. with no sender authentication.- Parameters:
recipientKey- public key of the recipientinfo- additional application-supplied information, may be null or empty- Throws:
java.security.InvalidKeyException- if recipientKey is null or an unsupported key formatjava.lang.UnsupportedOperationException- if mode is not a supported HPKE modejava.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.InvalidKeyExceptionInitialises this HpkeContextSender in AUTH mode, i.e. messages are authenticated using the sender's public key.- Parameters:
recipientKey- public key of the recipientinfo- additional application-supplied information, may be null or emptysenderKey- private key of the sender- Throws:
java.security.InvalidKeyException- if either recipientKey or senderKey are null or an unsupported key formatjava.lang.UnsupportedOperationException- if mode is not a supported HPKE modejava.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.InvalidKeyExceptionInitialises this HpkeContextSender in PSK mode, i.e. messages are authenticated using a pre-shared secret key.- Parameters:
recipientKey- public key of the recipientinfo- additional application-supplied information, may be null or emptypsk- the a pre-shared secret keypsk_id- the id of the pre-shared secret key- Throws:
java.lang.NullPointerException- if psk or psk_id are nulljava.security.InvalidKeyException- if recipientKey is null or an unsupported key formatjava.lang.UnsupportedOperationException- if mode is not a supported HPKE modejava.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.InvalidKeyExceptionInitialises 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 recipientinfo- additional application-supplied information, may be null or emptysenderKey- private key of the senderpsk- the a pre-shared secret keypsk_id- the id of the pre-shared secret key- Throws:
java.lang.NullPointerException- if psk or psk_id are nulljava.security.InvalidKeyException- if either recipientKey or senderKey are null or an unsupported key formatjava.lang.UnsupportedOperationException- if mode is not a supported HPKE modejava.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 recipientinfo- additional application-supplied information, may be null or emptysKe- random seed to use during testing- Throws:
java.security.InvalidKeyException- if recipientKey is null or an unsupported key formatjava.lang.UnsupportedOperationException- if mode is not a supported HPKE modejava.lang.IllegalStateException- if this HpkeContextSender has already been initialisedjava.lang.IllegalArgumentException- if sKe is null
-
-