public class HashCreatorImplDigest extends CryptoAlgorithmImpl implements HashCreator
HashCreator that only wraps MessageDigest.| Modifier and Type | Field and Description |
|---|---|
private MessageDigest |
digest |
provider| Constructor and Description |
|---|
HashCreatorImplDigest(String hashAlgorithm,
SecurityProvider provider)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected static MessageDigest |
getOrCloneMessageDigest(MessageDigest messageDigest,
boolean clone) |
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 new
OutputStream wraps the given OutputStream. |
getAlgorithmgetProvidercreationFailedException, creationFailedException, creationFailedException, creationFailedException, getAlgorithm, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waithash, hash, hash, hash, process, wrapStreamupdate, updateprocess, process, processgetAlgorithmprivate final MessageDigest digest
public HashCreatorImplDigest(String hashAlgorithm, SecurityProvider provider)
hashAlgorithm - the name of the hash algorithm to use (e.g. "SHA-256").provider - the SecurityProvider to use.public OutputStream wrapStream(OutputStream out)
HashCreatorOutputStream wraps the given OutputStream. It will automatically
update all written data. After data has been written,
you may call HashCreator.hash(boolean) to get the hash of the data. This method will not reset this
hasher. Therefore any previous updated data will also influence the hash. The typical usage
is to call this method once on a fresh instance of HashCreator, then write data to that stream and
finally get the hash.wrapStream in interface HashCreatorout - the OutputStream to wrap.OutputStream.HashCreator.wrapStream(),
DigestOutputStreampublic void update(byte[] input,
int offset,
int length)
update in interface CryptoChunkerinput - the next chunk of data.offset - the index where to start reading data from input.length - the number of bytes to read from input.MessageDigest.update(byte[], int, int),
Signature.update(byte[], int, int)public byte[] hash(boolean reset)
hash in interface HashCreatorreset - - true if this HashCreator shall be reset after the hash
calculation, false otherwise. A design problem of MessageDigest is that it
automatically resets itself on
hashing what prevents calculating intermediate hashes but also
continue the hash calculation. This API allows to workaround this limitation.MessageDigest.digest()protected static MessageDigest getOrCloneMessageDigest(MessageDigest messageDigest, boolean clone)
messageDigest - the original MessageDigest.clone - - true to return a clone or copy of the original MessageDigest, false
otherwise.MessageDigest or a clone of it in case the given clone flag
was true.public void reset()
CryptoProcessorCryptor may not reusable. It is therefore preferable to always create a
fresh instance for each cryptographic task.reset in interface CryptoProcessorMessageDigest.reset()Copyright © 2001–2019 mmm-Team. All rights reserved.