- 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)StringgetAlgorithm()protected CiphergetCipher()CryptorConfiggetConfig()protected StringgetMode()intgetNonceSize()UnlikeCipherthis API is designed for ease of use.protected abstract booleanisEncryptor()voidreset()Will reset the internal state of this object.protected RuntimeExceptionwrapSecurityException(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- theRandomFactoryto use.config- theCryptorConfig.key- theKeyto use.
-
-
Method Detail
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithmin 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:AbstractGetNonceSizeUnlikeCipherthis 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 forcryptand forstreaming.- Specified by:
getNonceSizein interfaceAbstractGetNonceSize- Returns:
- the size of the nonce in bytes or
0for 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:
cryptin interfaceCryptor- Parameters:
input- the next chunk of data to encrypt or decrypt.offset- the offset where to start in theinputarray.length- the number of bytes to read from theinputarray.complete- -trueto complete the encryption or decryption in case this is the last chunk of data,falseotherwise.- Returns:
- the number of bytes that have been written into the
outputarray. - See Also:
Cipher.update(byte[], int, int),Cipher.doFinal(byte[], int, int)
-
wrapSecurityException
protected RuntimeException wrapSecurityException(Exception e)
- Parameters:
e- theExceptionto wrap.- Returns:
- the wrapped
RuntimeException.
-
reset
public void reset()
Description copied from interface:CryptoProcessorWill reset the internal state of this object. Please note that complex algorithms especially forCryptormay not reusable. It is therefore preferable to always create a fresh instance for each cryptographic task.- Specified by:
resetin interfaceCryptoProcessor- See Also:
MessageDigest.reset()
-
-