Package org.conscrypt
Class HpkeContextSender
java.lang.Object
org.conscrypt.HpkeContext
org.conscrypt.HpkeContextSender
Hybrid Public Key Encryption (HPKE) sender APIs.
- See Also:
-
Field Summary
Fields inherited from class org.conscrypt.HpkeContext
spi -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the encapsulated key created for this HpkeContextSender.static HpkeContextSendergetInstance(String suite) Returns an uninitialised HpkeContextSender.static HpkeContextSendergetInstance(String suite, String providerName) Returns an uninitialised HpkeContextSender from a specificProviderstatic HpkeContextSendergetInstance(String suite, Provider provider) Returns an uninitialised HpkeContextSender from a specificProvidervoidInitialises this HpkeContextSender in BASE mode, i.e.voidInitialises this HpkeContextSender in PSK mode, i.e.voidinit(PublicKey recipientKey, byte[] info, PrivateKey senderKey) Initialises this HpkeContextSender in AUTH mode, i.e.voidinit(PublicKey recipientKey, byte[] info, PrivateKey senderKey, byte[] psk, byte[] psk_id) Initialises this HpkeContextSender in PSK_AUTH mode, i.e.voidinitForTesting(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 Details
-
HpkeContextSender
-
-
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 plaintextaad- optional associated data, may be null or empty- Returns:
- the ciphertext
- Throws:
NullPointerException- if the plaintext is nullIllegalStateException- if this HpkeContextSender has not been initialised
-
getInstance
Returns an uninitialised HpkeContextSender.- Parameters:
suite- the HPKE suite to use. @seeHpkeSuitefor 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 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:
NoSuchAlgorithmException- if no implementation could be foundNoSuchProviderException- 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 specificProvider- Parameters:
suite- the HPKE suite to use. @seeHpkeSuitefor details.provider- the Provider to use- Returns:
- an uninitialised HpkeContextSender for the requested suite
- Throws:
NoSuchAlgorithmException- if no implementation could be foundNoSuchProviderException- if provider is null
-
init
Initialises 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:
InvalidKeyException- if recipientKey is null or an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- 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 recipientinfo- additional application-supplied information, may be null or emptysenderKey- private key of the sender- Throws:
InvalidKeyException- if either recipientKey or senderKey are null or an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- 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 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:
NullPointerException- if psk or psk_id are nullInvalidKeyException- if recipientKey is null or an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- 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 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:
NullPointerException- if psk or psk_id are nullInvalidKeyException- if either recipientKey or senderKey are null or an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- 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 recipientinfo- additional application-supplied information, may be null or emptysKe- random seed to use during testing- Throws:
InvalidKeyException- if recipientKey is null or an unsupported key formatUnsupportedOperationException- if mode is not a supported HPKE modeIllegalStateException- if this HpkeContextSender has already been initialisedIllegalArgumentException- if sKe is null
-