Class BaseCipher
java.lang.Object
net.schmizz.sshj.transport.cipher.BaseCipher
- All Implemented Interfaces:
Cipher
- Direct Known Subclasses:
BlockCipher
,ChachaPolyCipher
,GcmCipher
,StreamCipher
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
int
int
protected 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 vectorprotected abstract void
initCipher
(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).
-
Field Details
-
ivsize
private final int ivsize -
bsize
private final int bsize -
algorithm
-
transformation
-
cipher
-
-
Constructor Details
-
BaseCipher
-
-
Method Details
-
resize
private static byte[] resize(byte[] data, int size) -
getBlockSize
public int getBlockSize()- Specified by:
getBlockSize
in interfaceCipher
- Returns:
- the block size for this cipher
-
getIVSize
public int getIVSize() -
getAuthenticationTagSize
public int getAuthenticationTagSize()- Specified by:
getAuthenticationTagSize
in interfaceCipher
- Returns:
- Size of the authentication tag (AT) in bytes or 0 if this cipher does not support authentication
-
init
Description copied from interface:Cipher
Initialize the cipher for encryption or decryption with the given private key and initialization vector -
initCipher
protected abstract void initCipher(Cipher cipher, Cipher.Mode mode, byte[] key, byte[] iv) throws InvalidKeyException, InvalidAlgorithmParameterException -
getKeySpec
-
getMode
-
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. -
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. -
updateAAD
public void updateAAD(byte[] data) Description copied from interface:Cipher
Adds 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: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 theaadLen
parameter are authenticated but not encrypted/decrypted, while payload data indicated by theinputLen
parameter are authenticated and encrypted/decrypted.- Specified by:
updateWithAAD
in 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:
setSequenceNumber
in interfaceCipher
-