Class EstablishedEcies

java.lang.Object
io.github.fherbreteau.vodozemac.NativeHandle
io.github.fherbreteau.vodozemac.ecies.EstablishedEcies
All Implemented Interfaces:
AutoCloseable

public final class EstablishedEcies extends NativeHandle
An established ECIES channel that can be used to encrypt and decrypt messages between the two sides of the channel.

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:

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 Details

    • publicKey

      public String publicKey()
      Returns our Curve25519 public key that was used to establish the ECIES channel.
      Returns:
      the base64-encoded public key
      Throws:
      IllegalStateException - if this EstablishedEcies has been closed
    • checkCode

      public CheckCode checkCode()
      Returns the CheckCode which 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 this EstablishedEcies has been closed
    • encrypt

      public String encrypt(byte[] plaintext)
      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 this EstablishedEcies has been closed
    • decrypt

      public byte[] decrypt(String message)
      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 this EstablishedEcies has been closed
      EciesException - if decryption fails, e.g. due to a corrupted message, a replayed message, or a key mismatch
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object