Class BaseCipher

java.lang.Object
org.apache.sshd.common.cipher.BaseCipher
All Implemented Interfaces:
AlgorithmNameProvider, Cipher, CipherInformation, KeySizeIndicator
Direct Known Subclasses:
BaseCBCCipher, BaseCTRCipher, BaseGCMCipher, BaseRC4Cipher

public class BaseCipher extends Object implements Cipher
Base class for all Cipher implementations delegating to the JCE provider.
  • Field Details

    • factory

      static BaseCipher.CipherFactory factory
    • alwaysReInit

      static boolean alwaysReInit
    • mode

      protected Cipher.Mode mode
    • cipher

      private Cipher cipher
    • ivsize

      private final int ivsize
    • authSize

      private final int authSize
    • kdfSize

      private final int kdfSize
    • algorithm

      private final String algorithm
    • keySize

      private final int keySize
    • blkSize

      private final int blkSize
    • transformation

      private final String transformation
    • s

      private String s
    • secretKey

      private SecretKey secretKey
  • Constructor Details

    • BaseCipher

      public BaseCipher(int ivsize, int authSize, int kdfSize, String algorithm, int keySize, String transformation, int blkSize)
  • Method Details

    • getAlgorithm

      public String getAlgorithm()
      Specified by:
      getAlgorithm in interface AlgorithmNameProvider
    • getKeySize

      public int getKeySize()
      Specified by:
      getKeySize in interface KeySizeIndicator
      Returns:
      The number of bits used in the key
    • getTransformation

      public String getTransformation()
      Specified by:
      getTransformation in interface CipherInformation
      Returns:
      The actual transformation used - e.g., AES/CBC/NoPadding
    • getIVSize

      public int getIVSize()
      Specified by:
      getIVSize in interface CipherInformation
      Returns:
      Size of the initialization vector (in bytes)
    • getAuthenticationTagSize

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

      public int getKdfSize()
      Specified by:
      getKdfSize in interface CipherInformation
      Returns:
      The block size (in bytes) used to derive the secret key for this cipher
    • getCipherBlockSize

      public int getCipherBlockSize()
      Specified by:
      getCipherBlockSize in interface CipherInformation
      Returns:
      Size of block data used by the cipher (in bytes). For stream ciphers this value is (currently) used to indicate some average work buffer size to be used for the automatic re-keying mechanism described in RFC 4253 - Section 9
    • init

      public void init(Cipher.Mode mode, byte[] key, byte[] iv) throws Exception
      Description copied from interface: Cipher
      Initialize the cipher for encryption or decryption with the given key and initialization vector
      Specified by:
      init in interface Cipher
      Parameters:
      mode - Encrypt/Decrypt initialization
      key - Key bytes
      iv - Initialization vector bytes
      Throws:
      Exception - If failed to initialize
    • getCipherInstance

      protected Cipher getCipherInstance()
    • createCipherInstance

      protected Cipher createCipherInstance(Cipher.Mode mode, byte[] key, byte[] iv) throws Exception
      Throws:
      Exception
    • initializeKeyData

      protected byte[] initializeKeyData(Cipher.Mode mode, byte[] key, int reqLen)
    • initializeIVData

      protected byte[] initializeIVData(Cipher.Mode mode, byte[] iv, int reqLen)
    • update

      public void update(byte[] input, int inputOffset, int inputLen) throws Exception
      Description copied from interface: Cipher
      Performs in-place encryption or decryption on the given data.
      Specified by:
      update in interface Cipher
      Parameters:
      input - The input/output bytes
      inputOffset - The offset of the data in the data buffer
      inputLen - The number of bytes to update, starting at the given offset; must be a multiple of the cipher's block size
      Throws:
      Exception - If failed to execute
    • reInit

      protected void reInit(byte[] processed, int offset, int length) throws InvalidKeyException, InvalidAlgorithmParameterException
      Throws:
      InvalidKeyException
      InvalidAlgorithmParameterException
    • determineNewParameters

      protected AlgorithmParameterSpec determineNewParameters(byte[] processed, int offset, int length)
    • updateAAD

      public void updateAAD(byte[] data, int offset, int length) throws Exception
      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
      Throws:
      Exception - If failed to execute
    • resize

      protected static byte[] resize(byte[] data, int size)
    • toString

      public String toString()
      Overrides:
      toString in class Object