Package org.cryptacular.bean
Class AbstractHashBean
java.lang.Object
org.cryptacular.bean.AbstractHashBean
- Direct Known Subclasses:
EncodingHashBean
,SimpleHashBean
Abstract base class for all hash beans.
- Author:
- Middleware Services
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.AbstractHashBean
(Spec<org.bouncycastle.crypto.Digest> digestSpec, int iterations) Creates a new instance by specifying all properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
compareInternal
(byte[] hash, Object... data) Compares the hash of the given data against a known hash output.Spec<org.bouncycastle.crypto.Digest>
int
protected byte[]
hashInternal
(Object... data) Hashes the given data.void
setDigestSpec
(Spec<org.bouncycastle.crypto.Digest> digestSpec) Sets the digest specification that determines the instance ofDigest
used to compute the hash.void
setIterations
(int iterations) Sets the number of iterations the digest function is applied to the input data.
-
Constructor Details
-
AbstractHashBean
public AbstractHashBean()Creates a new instance. -
AbstractHashBean
Creates a new instance by specifying all properties.- Parameters:
digestSpec
- Digest specification.iterations
- Number of hash rounds.
-
-
Method Details
-
getDigestSpec
- Returns:
- Digest specification that determines the instance of
Digest
used to compute the hash.
-
setDigestSpec
Sets the digest specification that determines the instance ofDigest
used to compute the hash.- Parameters:
digestSpec
- Digest algorithm specification.
-
getIterations
public int getIterations()- Returns:
- Number of iterations the digest function is applied to the input data.
-
setIterations
public void setIterations(int iterations) Sets the number of iterations the digest function is applied to the input data.- Parameters:
iterations
- Number of hash rounds. Default value is 1.
-
hashInternal
Hashes the given data.- Parameters:
data
- Data to hash.- Returns:
- Digest output.
-
compareInternal
Compares the hash of the given data against a known hash output.- Parameters:
hash
- Known hash value. If the length of the array is greater than the length of the digest output, anything beyond the digest length is considered salt data that is hashed after the input data.data
- Data to hash.- Returns:
- True if hashed data equals known hash output, false otherwise.
-