-
- 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 toMessageDigest
but 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 Hash
hash(CryptoBinary input, boolean reset)
default byte[]
process(byte[] input, int offset, int length, boolean complete)
Generic method to process and transform data.default OutputStream
wrapStream()
OutputStream
wrapStream(OutputStream out)
Creates a newOutputStream
wraps 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
OutputStream
that automaticallyupdates
allwritten
data. - See Also:
wrapStream(OutputStream)
-
wrapStream
OutputStream wrapStream(OutputStream out)
Creates a newOutputStream
wraps the givenOutputStream
. It will automaticallyupdate
allwritten
data. After data has been written, you may callhash(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
.- Parameters:
out
- theOutputStream
to 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:CryptoProcessor
Generic method to process and transform data.CryptoProcessor
Equivalent of process
(input, offset, length, complete)HashCreator
update
(input, offset, length); returnhash
(complete);Cryptor
return
crypt
(input, offset, length, true);SignatureSigner
update
(input, offset, length); returnsignAfterUpdate
(complete);SignatureVerifier
throw new
UnsupportedOperationException
();- Specified by:
process
in 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
- -true
to complete/reset this processor after processing the giveninput
,false
otherwise.- Returns:
- the transformed
input
data.
-
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
Hash
of the giveninput
data. - 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 thisHashCreator
after 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
- -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()
-
-