Class BaseCipher
- java.lang.Object
-
- net.schmizz.sshj.transport.cipher.BaseCipher
-
- All Implemented Interfaces:
Cipher
- Direct Known Subclasses:
BlockCipher,ChachaPolyCipher,GcmCipher,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
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.crypto.Ciphercipher
-
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 intgetAuthenticationTagSize()intgetBlockSize()intgetIVSize()protected javax.crypto.spec.SecretKeySpecgetKeySpec(byte[] key)protected intgetMode(Cipher.Mode mode)voidinit(Cipher.Mode mode, byte[] key, byte[] iv)Initialize the cipher for encryption or decryption with the given private key and initialization vectorprotected abstract voidinitCipher(javax.crypto.Cipher cipher, Cipher.Mode mode, byte[] key, byte[] iv)voidsetSequenceNumber(long seq)voidupdate(byte[] input, int inputOffset, int inputLen)Performs in-place encryption or decryption on the given data.voidupdateAAD(byte[] data)Adds the provided input data as additional authenticated data during encryption or decryption.voidupdateAAD(byte[] data, int offset, int length)Adds the provided input data as additional authenticated data during encryption or decryption.voidupdateWithAAD(byte[] input, int offset, int aadLen, int inputLen)Performs in-place authenticated encryption or decryption with additional data (AEAD).
-
-
-
Method Detail
-
getBlockSize
public int getBlockSize()
- Specified by:
getBlockSizein interfaceCipher- Returns:
- the block size for this cipher
-
getIVSize
public int getIVSize()
-
getAuthenticationTagSize
public int getAuthenticationTagSize()
- Specified by:
getAuthenticationTagSizein interfaceCipher- 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:CipherInitialize the cipher for encryption or decryption with the given private key and 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.InvalidKeyExceptionjava.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:CipherPerforms in-place encryption or decryption on the given data.
-
updateAAD
public void updateAAD(byte[] data, int offset, int length)Description copied from interface:CipherAdds the provided input data as additional authenticated data during encryption or decryption.
-
updateAAD
public void updateAAD(byte[] data)
Description copied from interface:CipherAdds the provided input data as additional authenticated data during encryption or decryption.
-
updateWithAAD
public void updateWithAAD(byte[] input, int offset, int aadLen, int inputLen)Description copied from interface:CipherPerforms 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 theaadLenparameter are authenticated but not encrypted/decrypted, while payload data indicated by theinputLenparameter are authenticated and encrypted/decrypted.- Specified by:
updateWithAADin interfaceCipher- Parameters:
input- The input/output bytesoffset- The offset of the data in the input bufferaadLen- The number of bytes to use as additional authenticated data - starting at offsetinputLen- The number of bytes to update - starting at offset + aadLen
-
setSequenceNumber
public void setSequenceNumber(long seq)
- Specified by:
setSequenceNumberin interfaceCipher
-
-