public class EncodingHashBean extends AbstractHashBean implements HashBean<String>
Constructor and Description |
---|
EncodingHashBean()
Creates a new instance.
|
EncodingHashBean(Spec<Codec> codecSpec,
Spec<org.bouncycastle.crypto.Digest> digestSpec)
Creates a new instance that will not be salted.
|
EncodingHashBean(Spec<Codec> codecSpec,
Spec<org.bouncycastle.crypto.Digest> digestSpec,
int iterations)
Creates a new instance that will not be salted.
|
EncodingHashBean(Spec<Codec> codecSpec,
Spec<org.bouncycastle.crypto.Digest> digestSpec,
int iterations,
boolean salted)
Creates a new instance by specifying all properties.
|
Modifier and Type | Method and Description |
---|---|
boolean |
compare(String hash,
Object... data)
Compares a known hash value with the hash of the given data.
|
Spec<Codec> |
getCodecSpec() |
String |
hash(Object... data)
Hashes the given data.
|
boolean |
isSalted()
Whether data provided to
hash(Object...) includes a salt as the last parameter. |
void |
setCodecSpec(Spec<Codec> codecSpec)
Sets the codec specification that determines the encoding applied to the hash output bytes.
|
void |
setSalted(boolean salted)
Sets whether
hash(Object...) should expect a salt as the last parameter. |
compareInternal, getDigestSpec, getIterations, hashInternal, setDigestSpec, setIterations
public EncodingHashBean()
public EncodingHashBean(Spec<Codec> codecSpec, Spec<org.bouncycastle.crypto.Digest> digestSpec)
EncodingHashBean(Spec, Spec, int, boolean)
.codecSpec
- Digest specification.digestSpec
- Digest specification.public EncodingHashBean(Spec<Codec> codecSpec, Spec<org.bouncycastle.crypto.Digest> digestSpec, int iterations)
EncodingHashBean(Spec, Spec, int, boolean)
.codecSpec
- Digest specification.digestSpec
- Digest specification.iterations
- Number of hash rounds.public EncodingHashBean(Spec<Codec> codecSpec, Spec<org.bouncycastle.crypto.Digest> digestSpec, int iterations, boolean salted)
codecSpec
- Digest specification.digestSpec
- Digest specification.iterations
- Number of hash rounds.salted
- Whether hash data will be salted.public Spec<Codec> getCodecSpec()
public void setCodecSpec(Spec<Codec> codecSpec)
codecSpec
- Codec specification, e.g. CodecSpec.BASE64
, CodecSpec.HEX
.public boolean isSalted()
hash(Object...)
includes a salt as the last parameter.public void setSalted(boolean salted)
hash(Object...)
should expect a salt as the last parameter.salted
- whether hash data includes a saltpublic String hash(Object... data) throws CryptoException, EncodingException, StreamException
isSalted()
is true then the last parameter MUST be a byte array containing the
salt. The salt value will be appended to the encoded hash that is returned.hash
in interface HashBean<String>
data
- Data to hash.CryptoException
- on hash computation errors.EncodingException
- on encoding errors.StreamException
- on stream IO errors.public boolean compare(String hash, Object... data) throws CryptoException, EncodingException, StreamException
compare
in interface HashBean<String>
hash
- Known encoded hash value. If the length of the hash bytes after decoding 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.CryptoException
- on hash computation errors.EncodingException
- on encoding errors.StreamException
- on stream IO errors.Copyright © 2003-2024 Virginia Tech. All Rights Reserved.