Class BaseCipher

  • All Implemented Interfaces:
    Cipher
    Direct Known Subclasses:
    BlockCipher, StreamCipher

    public abstract class BaseCipher
    extends java.lang.Object
    implements Cipher
    Base class for all Cipher implementations delegating to the JCE provider.
    • Nested Class Summary

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

        Cipher.Mode
    • Constructor Summary

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

      Modifier and Type Method Description
      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)  
      void update​(byte[] input, int inputOffset, int inputLen)
      Performs in-place encryption or decryption on the given data.
      • Methods inherited from class java.lang.Object

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

      • BaseCipher

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

      • 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
      • 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