- java.lang.Object
-
- io.github.mmm.crypto.algorithm.AbstractSecurityAlgorithm
-
- io.github.mmm.crypto.hash.HashCreatorImplCombined
-
- All Implemented Interfaces:
CryptoAlgorithm
,CryptoChunker
,CryptoProcessor
,HashCreator
public class HashCreatorImplCombined extends AbstractSecurityAlgorithm implements HashCreator
This is a simple implementation ofHashCreator
that only wrapsMessageDigest
.- Since:
- 1.0.0
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
-
-
Constructor Summary
Constructors Constructor Description HashCreatorImplCombined(HashCreator[] generators)
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAlgorithm()
byte[]
hash(boolean reset)
void
reset()
Will reset the internal state of this object.void
update(byte[] input, int offset, int length)
OutputStream
wrapStream(OutputStream out)
Creates a newOutputStream
wraps the givenOutputStream
.-
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.CryptoChunker
update, update
-
Methods inherited from interface io.github.mmm.crypto.CryptoProcessor
process, process, process
-
Methods inherited from interface io.github.mmm.crypto.hash.HashCreator
hash, hash, hash, hash, process, wrapStream
-
-
-
-
Constructor Detail
-
HashCreatorImplCombined
public HashCreatorImplCombined(HashCreator[] generators)
The constructor.- Parameters:
generators
- theHashCreator
s to combine sequentially.
-
-
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()
-
wrapStream
public OutputStream wrapStream(OutputStream out)
Description copied from interface:HashCreator
Creates a newOutputStream
wraps the givenOutputStream
. It will automaticallyupdate
allwritten
data. After data has been written, you may callHashCreator.hash(boolean)
to get the hash of the data. This method will notreset
this hasher. Therefore any previousupdated data
will also influence the hash. The typical usage is to call this method once on a fresh instance ofHashCreator
, then write data to that stream and finally get thehash
.- Specified by:
wrapStream
in interfaceHashCreator
- Parameters:
out
- theOutputStream
to wrap.- Returns:
- a wrapped
OutputStream
. - See Also:
HashCreator.wrapStream()
,DigestOutputStream
-
update
public void update(byte[] input, int offset, int length)
- Specified by:
update
in interfaceCryptoChunker
- Parameters:
input
- the next chunk of data.offset
- the index where to start reading data frominput
.length
- the number of bytes to read frominput
.- See Also:
MessageDigest.update(byte[], int, int)
,Signature.update(byte[], int, int)
-
hash
public byte[] hash(boolean reset)
- Specified by:
hash
in interfaceHashCreator
- Parameters:
reset
- -true
if thisHashCreator
shall bereset
after the hash calculation,false
otherwise. A design problem ofMessageDigest
is that it automaticallyresets
itself onhashing
what prevents calculating intermediate hashes but also continue the hash calculation. This API allows to workaround this limitation.- Returns:
- the calculated hash of the current data.
- See Also:
MessageDigest.digest()
-
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()
-
-