Class CryptoSession


  • public final class CryptoSession
    extends java.lang.Object
    A CryptoSession represents a cryptographic session with a peer (e.g. client or device) and is used to encrypt and decrypt messages sent and received, respectively.

    A CryptoSession is thread-safe.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String id  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] decrypt​(byte[] ciphertext)
      Decrypt a byte array containing ciphertext.
      byte[] encrypt​(byte[] plaintext)
      Encrypt a byte array containing plaintext.
      byte[] getRemoteFingerprint()
      Get the remote fingerprint as a hex-encoded byte array.
      boolean isClosed()  
      void save()
      Save the session, persisting any changes made to the underlying key material as a result of any encrypt(byte[]) and decrypt(byte[]) operations since the last save.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • id

        public final java.lang.String id
    • Method Detail

      • encrypt

        public byte[] encrypt​(byte[] plaintext)
                       throws CryptoException
        Encrypt a byte array containing plaintext.
        Parameters:
        plaintext - The plaintext to encrypt.
        Returns:
        A byte array containing the ciphertext.
        Throws:
        CryptoException
      • decrypt

        public byte[] decrypt​(byte[] ciphertext)
                       throws CryptoException
        Decrypt a byte array containing ciphertext.
        Parameters:
        ciphertext - The ciphertext to decrypt.
        Returns:
        A byte array containing the plaintext.
        Throws:
        CryptoException
      • getRemoteFingerprint

        public byte[] getRemoteFingerprint()
                                    throws CryptoException
        Get the remote fingerprint as a hex-encoded byte array.
        Throws:
        CryptoException
      • isClosed

        public boolean isClosed()