- java.lang.Object
-
- io.github.mmm.crypto.algorithm.AbstractSecurityAlgorithm
-
- io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
-
- io.github.mmm.crypto.algorithm.CryptoAlgorithmImpl
-
- io.github.mmm.crypto.hash.HashCreatorImplDigest
-
- All Implemented Interfaces:
CryptoAlgorithm,CryptoChunker,CryptoProcessor,HashCreator
- Direct Known Subclasses:
HashCreatorImplMultipleRounds
public class HashCreatorImplDigest extends CryptoAlgorithmImpl implements HashCreator
This is a simple implementation ofHashCreatorthat only wrapsMessageDigest.- 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 HashCreatorImplDigest(String hashAlgorithm, SecurityProvider provider)The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static MessageDigestgetOrCloneMessageDigest(MessageDigest messageDigest, boolean clone)byte[]hash(boolean reset)voidreset()Will reset the internal state of this object.voidupdate(byte[] input, int offset, int length)OutputStreamwrapStream(OutputStream out)Creates a newOutputStreamwraps the givenOutputStream.-
Methods inherited from class io.github.mmm.crypto.algorithm.CryptoAlgorithmImpl
getAlgorithm
-
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.algorithm.CryptoAlgorithm
getAlgorithm
-
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
-
HashCreatorImplDigest
public HashCreatorImplDigest(String hashAlgorithm, SecurityProvider provider)
The constructor.- Parameters:
hashAlgorithm- the name of the hash algorithm to use (e.g. "SHA-256").provider- theSecurityProviderto use.
-
-
Method Detail
-
wrapStream
public OutputStream wrapStream(OutputStream out)
Description copied from interface:HashCreatorCreates a newOutputStreamwraps the givenOutputStream. It will automaticallyupdateallwrittendata. After data has been written, you may callHashCreator.hash(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.- Specified by:
wrapStreamin interfaceHashCreator- Parameters:
out- theOutputStreamto wrap.- Returns:
- a wrapped
OutputStream. - See Also:
HashCreator.wrapStream(),DigestOutputStream
-
update
public void update(byte[] input, int offset, int length)- Specified by:
updatein 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:
hashin interfaceHashCreator- 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()
-
getOrCloneMessageDigest
protected static MessageDigest getOrCloneMessageDigest(MessageDigest messageDigest, boolean clone)
- Parameters:
messageDigest- the originalMessageDigest.clone- -trueto return a clone or copy of the originalMessageDigest,falseotherwise.- Returns:
- the original
MessageDigestor acloneof it in case the givencloneflag wastrue.
-
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()
-
-