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 int
BITSPERBYTE
How many bits in a byte.protected char[]
chPasswd
char array of password.protected int
currentIvLen
IV length.protected int
currentKeysize
Key size as defined by child class.protected int
currentSaltLen
Salt length.protected int
iterCount
Iterations count as defined by child class.protected byte[]
ivBytes
IV bytes.protected javax.crypto.SecretKeyFactory
keyFac
SecretKeyFactory.protected javax.crypto.SecretKey
pbeKey
SecretKey.protected javax.crypto.spec.PBEKeySpec
pbeKeySpec
PBEKeySpec.protected javax.crypto.spec.SecretKeySpec
pbeSecretKeySpec
SecretKeySpec.protected byte[]
salt
salt.protected java.lang.String
strAlg
ALG for the data.protected java.lang.String
strKeyAlg
Algorithm 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 void
decStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
decode Stream function.void
encodeAndDecode(java.io.InputStream inputStream, java.io.OutputStream outputStream)
Local encode Stream function which does the real thing for Random Layer.void
encStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
encode Stream function.protected void
getIv()
store IV bytes.protected abstract java.lang.String
getMyAlg()
Abstract base method for getting algorithm name back.protected abstract int
getMyCount()
Abstract base method for getting a counter back.protected abstract int
getMyIvLen()
Abstract base method for getting IV length back.protected abstract java.lang.String
getMyKeyAlg()
Abstract base method for getting key algorithm name back.protected abstract int
getMyKeysize()
Abstract base method for getting key size back.protected abstract int
getMySaltLen()
Abstract base method for getting salt len back.protected void
getSalt()
Generate random salt.protected void
init()
Set base values via own getters, which are defined in child classes.protected abstract void
setupPbe()
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 JastacryException
Generate Keys from plain password.- Throws:
JastacryException
- on error
-
encStream
public final void encStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws JastacryException
encode 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 JastacryException
decode 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 JastacryException
Description copied from interface:Layer
Local encode Stream function which does the real thing for Random Layer.- Parameters:
inputStream
- incoming dataoutputStream
- outgoing data- Throws:
JastacryException
- thrown on error
-
-