Package org.apache.sshd.common.cipher
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 java.lang.Object implements Cipher
Base class for all Cipher implementations delegating to the JCE provider.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceBaseCipher.CipherFactory-
Nested classes/interfaces inherited from interface org.apache.sshd.common.cipher.Cipher
Cipher.Mode
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringalgorithm(package private) static booleanalwaysReInitprivate intauthSizeprivate intblkSizeprivate javax.crypto.Ciphercipher(package private) static BaseCipher.CipherFactoryfactoryprivate intivsizeprivate intkdfSizeprivate intkeySizeprotected Cipher.Modemodeprivate java.lang.Stringsprivate javax.crypto.SecretKeysecretKeyprivate java.lang.Stringtransformation
-
Constructor Summary
Constructors Constructor Description BaseCipher(int ivsize, int authSize, int kdfSize, java.lang.String algorithm, int keySize, java.lang.String transformation, int blkSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.crypto.CiphercreateCipherInstance(Cipher.Mode mode, byte[] key, byte[] iv)protected java.security.spec.AlgorithmParameterSpecdetermineNewParameters(byte[] processed, int offset, int length)java.lang.StringgetAlgorithm()intgetAuthenticationTagSize()intgetCipherBlockSize()protected javax.crypto.CiphergetCipherInstance()intgetIVSize()intgetKdfSize()intgetKeySize()java.lang.StringgetTransformation()voidinit(Cipher.Mode mode, byte[] key, byte[] iv)Initialize the cipher for encryption or decryption with the given key and initialization vectorprotected byte[]initializeIVData(Cipher.Mode mode, byte[] iv, int reqLen)protected byte[]initializeKeyData(Cipher.Mode mode, byte[] key, int reqLen)protected voidreInit(byte[] processed, int offset, int length)protected static byte[]resize(byte[] data, int size)java.lang.StringtoString()voidupdate(byte[] input, int inputOffset, int inputLen)Performs in-place encryption or decryption on the given data.voidupdateAAD(byte[] data, int offset, int length)Adds the provided input data as additional authenticated data during encryption or decryption.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.cipher.Cipher
update, updateAAD, updateWithAAD
-
-
-
-
Field Detail
-
factory
static BaseCipher.CipherFactory factory
-
alwaysReInit
static boolean alwaysReInit
-
mode
protected Cipher.Mode mode
-
cipher
private javax.crypto.Cipher cipher
-
ivsize
private final int ivsize
-
authSize
private final int authSize
-
kdfSize
private final int kdfSize
-
algorithm
private final java.lang.String algorithm
-
keySize
private final int keySize
-
blkSize
private final int blkSize
-
transformation
private final java.lang.String transformation
-
s
private java.lang.String s
-
secretKey
private javax.crypto.SecretKey secretKey
-
-
Method Detail
-
getAlgorithm
public java.lang.String getAlgorithm()
- Specified by:
getAlgorithmin interfaceAlgorithmNameProvider
-
getKeySize
public int getKeySize()
- Specified by:
getKeySizein interfaceKeySizeIndicator- Returns:
- The number of bits used in the key
-
getTransformation
public java.lang.String getTransformation()
- Specified by:
getTransformationin interfaceCipherInformation- Returns:
- The actual transformation used - e.g., AES/CBC/NoPadding
-
getIVSize
public int getIVSize()
- Specified by:
getIVSizein interfaceCipherInformation- Returns:
- Size of the initialization vector (in bytes)
-
getAuthenticationTagSize
public int getAuthenticationTagSize()
- Specified by:
getAuthenticationTagSizein interfaceCipherInformation- Returns:
- Size of the authentication tag (AT) in bytes or 0 if this cipher does not support authentication
-
getKdfSize
public int getKdfSize()
- Specified by:
getKdfSizein interfaceCipherInformation- Returns:
- The block size (in bytes) used to derive the secret key for this cipher
-
getCipherBlockSize
public int getCipherBlockSize()
- Specified by:
getCipherBlockSizein interfaceCipherInformation- 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 java.lang.Exception
Description copied from interface:CipherInitialize the cipher for encryption or decryption with the given key and initialization vector
-
getCipherInstance
protected javax.crypto.Cipher getCipherInstance()
-
createCipherInstance
protected javax.crypto.Cipher createCipherInstance(Cipher.Mode mode, byte[] key, byte[] iv) throws java.lang.Exception
- Throws:
java.lang.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 java.lang.ExceptionDescription copied from interface:CipherPerforms in-place encryption or decryption on the given data.- Specified by:
updatein interfaceCipher- Parameters:
input- The input/output bytesinputOffset- The offset of the data in the data bufferinputLen- The number of bytes to update, starting at the given offset; must be a multiple of the cipher's block size- Throws:
java.lang.Exception- If failed to execute
-
reInit
protected void reInit(byte[] processed, int offset, int length) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException- Throws:
java.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterException
-
determineNewParameters
protected java.security.spec.AlgorithmParameterSpec determineNewParameters(byte[] processed, int offset, int length)
-
updateAAD
public void updateAAD(byte[] data, int offset, int length) throws java.lang.ExceptionDescription copied from interface:CipherAdds the provided input data as additional authenticated data during encryption or decryption.
-
resize
protected static byte[] resize(byte[] data, int size)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-