- java.lang.Object
-
- io.github.mmm.crypto.algorithm.AbstractSecurityAlgorithm
-
- io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
-
- io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithRandom
-
- io.github.mmm.crypto.crypt.CryptorImplCipher
-
- All Implemented Interfaces:
CryptoAlgorithm
,AbstractGetNonceSize
,Cryptor
,CryptoProcessor
- Direct Known Subclasses:
DecryptorImplCipher
,EncryptorImplCiper
public abstract class CryptorImplCipher extends AbstractCryptoAlgorithmWithRandom implements Cryptor
- Since:
- 1.0.0
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
-
-
Field Summary
-
Fields inherited from class io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
provider
-
-
Constructor Summary
Constructors Constructor Description CryptorImplCipher(RandomFactory randomFactory, CryptorConfig config, Key key)
The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description byte[]
crypt(byte[] input, int offset, int length, boolean complete)
String
getAlgorithm()
protected Cipher
getCipher()
CryptorConfig
getConfig()
protected String
getMode()
int
getNonceSize()
UnlikeCipher
this API is designed for ease of use.protected abstract boolean
isEncryptor()
void
reset()
Will reset the internal state of this object.protected RuntimeException
wrapSecurityException(Exception e)
-
Methods inherited from class io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithRandom
createSecureRandom, getRandomFactory
-
Methods inherited from class io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
getProvider
-
Methods inherited from class io.github.mmm.crypto.algorithm.AbstractSecurityAlgorithm
creationFailedException, creationFailedException, creationFailedException, creationFailedException, getAlgorithm, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.crypto.CryptoProcessor
process, process, process
-
-
-
-
Constructor Detail
-
CryptorImplCipher
public CryptorImplCipher(RandomFactory randomFactory, CryptorConfig config, Key key)
The constructor.- Parameters:
randomFactory
- theRandomFactory
to use.config
- theCryptorConfig
.key
- theKey
to use.
-
-
Method Detail
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceCryptoAlgorithm
- Returns:
- the name of the underlying algorithm (e.g. "RSA", "NONEwithECDSA", etc.).
- See Also:
Key.getAlgorithm()
,Signature.getAlgorithm()
,MessageDigest.getAlgorithm()
,SecureRandom.getAlgorithm()
,Cipher.getAlgorithm()
-
getNonceSize
public int getNonceSize()
Description copied from interface:AbstractGetNonceSize
UnlikeCipher
this API is designed for ease of use. Some cryptographic algorithms require aninitialization vector
(IV) and others do not. With this API you do not have to care and cannot do things wrong. The nonce will be prepended automatically to the encrypted payload and reconstructed from there on decryption. This works both forcrypt
and forstreaming
.- Specified by:
getNonceSize
in interfaceAbstractGetNonceSize
- Returns:
- the size of the nonce in bytes or
0
for none. - See Also:
Cipher.getIV()
-
isEncryptor
protected abstract boolean isEncryptor()
-
getConfig
public final CryptorConfig getConfig()
- Returns:
- the
CryptorConfig
.
-
getMode
protected String getMode()
-
crypt
public byte[] crypt(byte[] input, int offset, int length, boolean complete)
- Specified by:
crypt
in interfaceCryptor
- Parameters:
input
- the next chunk of data to encrypt or decrypt.offset
- the offset where to start in theinput
array.length
- the number of bytes to read from theinput
array.complete
- -true
to complete the encryption or decryption in case this is the last chunk of data,false
otherwise.- Returns:
- the number of bytes that have been written into the
output
array. - See Also:
Cipher.update(byte[], int, int)
,Cipher.doFinal(byte[], int, int)
-
wrapSecurityException
protected RuntimeException wrapSecurityException(Exception e)
- Parameters:
e
- theException
to wrap.- Returns:
- the wrapped
RuntimeException
.
-
reset
public void reset()
Description copied from interface:CryptoProcessor
Will reset the internal state of this object. Please note that complex algorithms especially forCryptor
may not reusable. It is therefore preferable to always create a fresh instance for each cryptographic task.- Specified by:
reset
in interfaceCryptoProcessor
- See Also:
MessageDigest.reset()
-
-