-
- All Superinterfaces:
CryptoAlgorithm,CryptoChunker,CryptoProcessor
- All Known Implementing Classes:
HashCreatorImplCombined,HashCreatorImplDigest,HashCreatorImplMultipleRounds
public interface HashCreator extends CryptoChunker
This is the interface for a creator of hash values. It is similar toMessageDigestbut allows additional features like hashing in multiple rounds (hashing of hashes) and gives additional abstraction as well as flexibility.- Since:
- 1.0.0
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default byte[]hash()This method calculates the current hash in the cheapest way of the underlying implementation.byte[]hash(boolean reset)default byte[]hash(byte[] input, boolean reset)default byte[]hash(byte[] input, int offset, int length, boolean reset)default Hashhash(CryptoBinary input, boolean reset)default byte[]process(byte[] input, int offset, int length, boolean complete)Generic method to process and transform data.default OutputStreamwrapStream()OutputStreamwrapStream(OutputStream out)Creates a newOutputStreamwraps the givenOutputStream.-
Methods inherited from interface io.github.mmm.crypto.algorithm.CryptoAlgorithm
getAlgorithm
-
Methods inherited from interface io.github.mmm.crypto.CryptoChunker
update, update, update
-
Methods inherited from interface io.github.mmm.crypto.CryptoProcessor
process, process, process, reset
-
-
-
-
Method Detail
-
wrapStream
default OutputStream wrapStream()
- Returns:
- a new
OutputStreamthat automaticallyupdatesallwrittendata. - See Also:
wrapStream(OutputStream)
-
wrapStream
OutputStream wrapStream(OutputStream out)
Creates a newOutputStreamwraps the givenOutputStream. It will automaticallyupdateallwrittendata. After data has been written, you may callhash(boolean)to get the hash of the data. This method will notresetthis hasher. Therefore any previousupdated datawill 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.- Parameters:
out- theOutputStreamto wrap.- Returns:
- a wrapped
OutputStream. - See Also:
wrapStream(),DigestOutputStream
-
process
default byte[] process(byte[] input, int offset, int length, boolean complete)Description copied from interface:CryptoProcessorGeneric method to process and transform data.CryptoProcessorEquivalent of process(input, offset, length, complete)HashCreatorupdate(input, offset, length); returnhash(complete);Cryptorreturncrypt(input, offset, length, true);SignatureSignerupdate(input, offset, length); returnsignAfterUpdate(complete);SignatureVerifierthrow newUnsupportedOperationException();- Specified by:
processin interfaceCryptoProcessor- Parameters:
input- the data to process.offset- the index where to start reading data frominput.length- the number of bytes to read frominput.complete- -trueto complete/reset this processor after processing the giveninput,falseotherwise.- Returns:
- the transformed
inputdata.
-
hash
default byte[] hash(byte[] input, boolean reset)- Parameters:
input- the data to hash.reset- - seehash(boolean).- Returns:
- the calculated hash of the current data.
- See Also:
MessageDigest.digest(byte[], int, int)
-
hash
default Hash hash(CryptoBinary input, boolean reset)
- Parameters:
input- the data to hash.reset- - seehash(boolean).- Returns:
- the calculated
Hashof the giveninputdata. - See Also:
MessageDigest.digest(byte[], int, int)
-
hash
default byte[] hash(byte[] input, int offset, int length, boolean reset)- Parameters:
input- the data to hash.offset- the index where to start reading data frominput.length- the number of bytes to read frominput.reset- - seehash(boolean).- Returns:
- the calculated hash of the current data.
- See Also:
MessageDigest.digest(byte[], int, int)
-
hash
default byte[] hash()
This method calculates the current hash in the cheapest way of the underlying implementation. The state of thisHashCreatorafter the call of this method is therefore unspecified. Use this method only if you do not care about the further state of thisHashCreator. Otherwise usehash(boolean)instead.- Returns:
- the calculated hash of the current data.
- See Also:
MessageDigest.digest()
-
hash
byte[] hash(boolean reset)
- Parameters:
reset- -trueif thisHashCreatorshall beresetafter the hash calculation,falseotherwise. A design problem ofMessageDigestis that it automaticallyresetsitself onhashingwhat 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()
-
-