Package org.jastacry.layer
Class AbstractCipherLayer
- java.lang.Object
-
- org.jastacry.layer.AbstractBasicLayer
-
- org.jastacry.layer.AbstractCipherLayer
-
- All Implemented Interfaces:
java.lang.Runnable,Layer
- Direct Known Subclasses:
AesCbcLayer,AesCtrLayer,AesEcbLayer,Md5DesLayer
public abstract class AbstractCipherLayer extends AbstractBasicLayer
Abstract base class for encryption.SPDX-License-Identifier: MIT
- Author:
- Kai Kretschmann
-
-
Field Summary
Fields Modifier and Type Field Description protected static intBITSPERBYTEHow many bits in a byte.protected char[]chPasswdchar array of password.protected intcurrentIvLenIV length.protected intcurrentKeysizeKey size as defined by child class.protected intcurrentSaltLenSalt length.protected intiterCountIterations count as defined by child class.protected byte[]ivBytesIV bytes.protected javax.crypto.SecretKeyFactorykeyFacSecretKeyFactory.protected javax.crypto.SecretKeypbeKeySecretKey.protected javax.crypto.spec.PBEKeySpecpbeKeySpecPBEKeySpec.protected javax.crypto.spec.SecretKeySpecpbeSecretKeySpecSecretKeySpec.protected byte[]saltsalt.protected java.lang.StringstrAlgALG for the data.protected java.lang.StringstrKeyAlgAlgorithm for the key.-
Fields inherited from class org.jastacry.layer.AbstractBasicLayer
endController, inputStream, logger, outputStream
-
-
Constructor Summary
Constructors Constructor Description AbstractCipherLayer(java.lang.Class<?> cClass, java.lang.String layerName)Constructor of abstract class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddecStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)decode Stream function.voidencodeAndDecode(java.io.InputStream inputStream, java.io.OutputStream outputStream)Local encode Stream function which does the real thing for Random Layer.voidencStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)encode Stream function.protected voidgetIv()store IV bytes.protected abstract java.lang.StringgetMyAlg()Abstract base method for getting algorithm name back.protected abstract intgetMyCount()Abstract base method for getting a counter back.protected abstract intgetMyIvLen()Abstract base method for getting IV length back.protected abstract java.lang.StringgetMyKeyAlg()Abstract base method for getting key algorithm name back.protected abstract intgetMyKeysize()Abstract base method for getting key size back.protected abstract intgetMySaltLen()Abstract base method for getting salt len back.protected voidgetSalt()Generate random salt.protected voidinit()Set base values via own getters, which are defined in child classes.protected abstract voidsetupPbe()Generate Keys from plain password.-
Methods inherited from class org.jastacry.layer.AbstractBasicLayer
rangeCheck, run, setAction, setEndController, setInputStream, setOutputStream, setRealLayerName, toString
-
-
-
-
Field Detail
-
BITSPERBYTE
protected static final int BITSPERBYTE
How many bits in a byte.- See Also:
- Constant Field Values
-
pbeKeySpec
protected javax.crypto.spec.PBEKeySpec pbeKeySpec
PBEKeySpec.
-
keyFac
protected javax.crypto.SecretKeyFactory keyFac
SecretKeyFactory.
-
pbeKey
protected javax.crypto.SecretKey pbeKey
SecretKey.
-
pbeSecretKeySpec
protected javax.crypto.spec.SecretKeySpec pbeSecretKeySpec
SecretKeySpec.
-
strAlg
protected java.lang.String strAlg
ALG for the data.
-
strKeyAlg
protected java.lang.String strKeyAlg
Algorithm for the key.
-
chPasswd
protected char[] chPasswd
char array of password.
-
iterCount
protected int iterCount
Iterations count as defined by child class.
-
currentKeysize
protected int currentKeysize
Key size as defined by child class.
-
currentIvLen
protected int currentIvLen
IV length.
-
ivBytes
protected byte[] ivBytes
IV bytes.
-
currentSaltLen
protected int currentSaltLen
Salt length.
-
salt
protected byte[] salt
salt.
-
-
Method Detail
-
getMyAlg
protected abstract java.lang.String getMyAlg()
Abstract base method for getting algorithm name back.- Returns:
- String
-
getMyKeyAlg
protected abstract java.lang.String getMyKeyAlg()
Abstract base method for getting key algorithm name back.- Returns:
- String
-
getMySaltLen
protected abstract int getMySaltLen()
Abstract base method for getting salt len back.- Returns:
- int length
-
getMyIvLen
protected abstract int getMyIvLen()
Abstract base method for getting IV length back.- Returns:
- int length
-
getMyCount
protected abstract int getMyCount()
Abstract base method for getting a counter back.- Returns:
- int
-
getMyKeysize
protected abstract int getMyKeysize()
Abstract base method for getting key size back.- Returns:
- int length
-
getSalt
protected final void getSalt()
Generate random salt.
-
getIv
protected final void getIv()
store IV bytes.
-
init
protected final void init()
Set base values via own getters, which are defined in child classes.
-
setupPbe
protected abstract void setupPbe() throws JastacryExceptionGenerate Keys from plain password.- Throws:
JastacryException- on error
-
encStream
public final void encStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws JastacryExceptionencode Stream function.- Parameters:
inputStream- incoming dataoutputStream- outgoing data- Throws:
JastacryException- thrown on error
-
decStream
public final void decStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws JastacryExceptiondecode Stream function.- Parameters:
inputStream- incoming dataoutputStream- outgoing data- Throws:
JastacryException- thrown on error
-
encodeAndDecode
public final void encodeAndDecode(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws JastacryExceptionDescription copied from interface:LayerLocal encode Stream function which does the real thing for Random Layer.- Parameters:
inputStream- incoming dataoutputStream- outgoing data- Throws:
JastacryException- thrown on error
-
-