Package org.cryptacular.bean
Class EncodingHashBean
java.lang.Object
org.cryptacular.bean.AbstractHashBean
org.cryptacular.bean.EncodingHashBean
- All Implemented Interfaces:
HashBean<CharSequence>
Computes a hash in an encoded format, e.g. hex, base64.
- Author:
- Middleware Services
-
Constructor Summary
ConstructorsConstructorDescriptionEncodingHashBean(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 encoding hash bean. -
Method Summary
Modifier and TypeMethodDescriptionbooleancompare(CharSequence hash, Object... data) Compares a known hash value with the hash of the given data.Hashes the given data.booleanisSalted()Whether data provided tohash(Object...)includes a salt as the last parameter.Methods inherited from class org.cryptacular.bean.AbstractHashBean
compareInternal, getDigestSpec, getIterations, hashInternal
-
Constructor Details
-
EncodingHashBean
Creates a new instance that will not be salted. Delegates toEncodingHashBean(Spec, Spec, int, boolean).- Parameters:
codecSpec- Digest specification.digestSpec- Digest specification.
-
EncodingHashBean
public EncodingHashBean(Spec<Codec> codecSpec, Spec<org.bouncycastle.crypto.Digest> digestSpec, int iterations) Creates a new instance that will not be salted. Delegates toEncodingHashBean(Spec, Spec, int, boolean).- Parameters:
codecSpec- Digest specification.digestSpec- Digest specification.iterations- Number of hash rounds.
-
EncodingHashBean
public EncodingHashBean(Spec<Codec> codecSpec, Spec<org.bouncycastle.crypto.Digest> digestSpec, int iterations, boolean salted) Creates a new encoding hash bean.- Parameters:
codecSpec- Digest specification.digestSpec- Digest specification.iterations- Number of hash rounds.salted- Whether hash data will be salted.
-
-
Method Details
-
getCodecSpec
- Returns:
- Codec specification that determines the encoding applied to the hash output bytes.
-
isSalted
public boolean isSalted()Whether data provided tohash(Object...)includes a salt as the last parameter.- Returns:
- whether hash data includes a salt
-
hash
Hashes the given data. IfisSalted()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.- Specified by:
hashin interfaceHashBean<CharSequence>- Parameters:
data- Data to hash.- Returns:
- Encoded digest output, including a salt if provided.
- Throws:
CryptoException- on hash computation errors.EncodingException- on encoding errors.StreamException- on stream IO errors.
-
compare
public boolean compare(CharSequence hash, Object... data) throws CryptoException, EncodingException, StreamException Compares a known hash value with the hash of the given data.- Specified by:
comparein interfaceHashBean<CharSequence>- Parameters:
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.- Returns:
- True if the hashed data matches the given hash, false otherwise.
- Throws:
CryptoException- on hash computation errors.EncodingException- on encoding errors.StreamException- on stream IO errors.
-