Class EstablishedEcies
- All Implemented Interfaces:
AutoCloseable
An EstablishedEcies is obtained by calling
Ecies.establishOutboundChannel(String, byte[]) on the initiator side
or Ecies.establishInboundChannel(String) on the recipient side. Once
established, it can be used to:
- Encrypt and decrypt messages using ChaCha20-Poly1305 via
encrypt(byte[])anddecrypt(String) - Retrieve the
CheckCodefor out-of-band MITM verification viacheckCode() - Retrieve the Curve25519 public key via
publicKey()
The encryption and decryption operations use internal nonce counters that increment with each message. Messages must be decrypted in the same order they were encrypted.
This class implements AutoCloseable and should be used in a
try-with-resources block to ensure native resources are properly released.
- Author:
- François HERBRETEAU
-
Method Summary
Modifier and TypeMethodDescriptionReturns theCheckCodewhich uniquely identifies this ECIES session.byte[]Decrypts the given message using this ECIES session.encrypt(byte[] plaintext) Encrypts the given plaintext using this ECIES session.booleaninthashCode()Returns our Curve25519 public key that was used to establish the ECIES channel.Methods inherited from class NativeHandle
checkNotClosed, close, invalidate, nativePtr
-
Method Details
-
publicKey
Returns our Curve25519 public key that was used to establish the ECIES channel.- Returns:
- the base64-encoded public key
- Throws:
IllegalStateException- if thisEstablishedEcieshas been closed
-
checkCode
Returns theCheckCodewhich uniquely identifies this ECIES session.The check code can be used to verify that both sides of the session are using the same shared secret. It should be shared out-of-band to protect against active man-in-the-middle (MITM) attacks.
- Returns:
- the check code
- Throws:
IllegalStateException- if thisEstablishedEcieshas been closed
-
encrypt
Encrypts the given plaintext using this ECIES session.The ciphertext is returned as a base64-encoded string. Each call to this method uses an incrementing nonce, so messages must be decrypted in the same order they were encrypted.
- Parameters:
plaintext- the plaintext to encrypt- Returns:
- the encrypted message as a base64-encoded string
- Throws:
IllegalStateException- if thisEstablishedEcieshas been closed
-
decrypt
Decrypts the given message using this ECIES session.The message must be a base64-encoded string produced by
encrypt(byte[])on the other side. Each call to this method uses an incrementing nonce, so messages must be decrypted in the same order they were encrypted by the sender.- Parameters:
message- the encrypted message as a base64-encoded string- Returns:
- the decrypted plaintext
- Throws:
IllegalStateException- if thisEstablishedEcieshas been closedEciesException- if decryption fails, e.g. due to a corrupted message, a replayed message, or a key mismatch
-
equals
-
hashCode
-