Class BaseCipher

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface net.schmizz.sshj.transport.cipher.Cipher

        Cipher.Mode
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String algorithm  
      private int bsize  
      protected javax.crypto.Cipher cipher  
      private int ivsize  
      private java.lang.String transformation  
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseCipher​(int ivsize, int bsize, java.lang.String algorithm, java.lang.String transformation)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      int getAuthenticationTagSize()  
      int getBlockSize()  
      int getIVSize()  
      protected javax.crypto.spec.SecretKeySpec getKeySpec​(byte[] key)  
      protected int getMode​(Cipher.Mode mode)  
      void init​(Cipher.Mode mode, byte[] key, byte[] iv)
      Initialize the cipher for encryption or decryption with the given private key and initialization vector
      protected abstract void initCipher​(javax.crypto.Cipher cipher, Cipher.Mode mode, byte[] key, byte[] iv)  
      private static byte[] resize​(byte[] data, int size)  
      void setSequenceNumber​(long seq)  
      void update​(byte[] input, int inputOffset, int inputLen)
      Performs in-place encryption or decryption on the given data.
      void updateAAD​(byte[] data)
      Adds the provided input data as additional authenticated data during encryption or decryption.
      void updateAAD​(byte[] data, int offset, int length)
      Adds the provided input data as additional authenticated data during encryption or decryption.
      void updateWithAAD​(byte[] input, int offset, int aadLen, int inputLen)
      Performs in-place authenticated encryption or decryption with additional data (AEAD).
      • Methods inherited from class java.lang.Object

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

      • ivsize

        private final int ivsize
      • bsize

        private final int bsize
      • algorithm

        private final java.lang.String algorithm
      • transformation

        private final java.lang.String transformation
      • cipher

        protected javax.crypto.Cipher cipher
    • Constructor Detail

      • BaseCipher

        public BaseCipher​(int ivsize,
                          int bsize,
                          java.lang.String algorithm,
                          java.lang.String transformation)
    • Method Detail

      • resize

        private static byte[] resize​(byte[] data,
                                     int size)
      • getBlockSize

        public int getBlockSize()
        Specified by:
        getBlockSize in interface Cipher
        Returns:
        the block size for this cipher
      • getIVSize

        public int getIVSize()
        Specified by:
        getIVSize in interface Cipher
        Returns:
        the size of the initialization vector
      • getAuthenticationTagSize

        public int getAuthenticationTagSize()
        Specified by:
        getAuthenticationTagSize in interface Cipher
        Returns:
        Size of the authentication tag (AT) in bytes or 0 if this cipher does not support authentication
      • init

        public void init​(Cipher.Mode mode,
                         byte[] key,
                         byte[] iv)
        Description copied from interface: Cipher
        Initialize the cipher for encryption or decryption with the given private key and initialization vector
        Specified by:
        init in interface Cipher
        Parameters:
        mode - whether this instance wil encrypt or decrypt
        key - the key for the cipher
        iv - initialization vector
      • initCipher

        protected abstract void initCipher​(javax.crypto.Cipher cipher,
                                           Cipher.Mode mode,
                                           byte[] key,
                                           byte[] iv)
                                    throws java.security.InvalidKeyException,
                                           java.security.InvalidAlgorithmParameterException
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • getKeySpec

        protected javax.crypto.spec.SecretKeySpec getKeySpec​(byte[] key)
      • getMode

        protected int getMode​(Cipher.Mode mode)
      • update

        public void update​(byte[] input,
                           int inputOffset,
                           int inputLen)
        Description copied from interface: Cipher
        Performs in-place encryption or decryption on the given data.
        Specified by:
        update in interface Cipher
        Parameters:
        input - the subject
        inputOffset - offset at which to start
        inputLen - number of bytes starting at inputOffset
      • updateAAD

        public void updateAAD​(byte[] data,
                              int offset,
                              int length)
        Description copied from interface: Cipher
        Adds the provided input data as additional authenticated data during encryption or decryption.
        Specified by:
        updateAAD in interface Cipher
        Parameters:
        data - The additional data to authenticate
        offset - The offset of the additional data in the buffer
        length - The number of bytes in the buffer to use for authentication
      • updateAAD

        public void updateAAD​(byte[] data)
        Description copied from interface: Cipher
        Adds the provided input data as additional authenticated data during encryption or decryption.
        Specified by:
        updateAAD in interface Cipher
        Parameters:
        data - The data to authenticate
      • updateWithAAD

        public void updateWithAAD​(byte[] input,
                                  int offset,
                                  int aadLen,
                                  int inputLen)
        Description copied from interface: Cipher
        Performs in-place authenticated encryption or decryption with additional data (AEAD). Authentication tags are implicitly appended after the output ciphertext or implicitly verified after the input ciphertext. Header data indicated by the aadLen parameter are authenticated but not encrypted/decrypted, while payload data indicated by the inputLen parameter are authenticated and encrypted/decrypted.
        Specified by:
        updateWithAAD in interface Cipher
        Parameters:
        input - The input/output bytes
        offset - The offset of the data in the input buffer
        aadLen - The number of bytes to use as additional authenticated data - starting at offset
        inputLen - The number of bytes to update - starting at offset + aadLen
      • setSequenceNumber

        public void setSequenceNumber​(long seq)
        Specified by:
        setSequenceNumber in interface Cipher