public final class HashUtil extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
compareHash(org.bouncycastle.crypto.Digest digest,
byte[] hash,
int iterations,
Object... data)
Determines whether the hash of the given input equals a known value.
|
static boolean |
compareHash(org.bouncycastle.crypto.Digest digest,
SaltedHash hash,
int iterations,
boolean saltAfterData,
Object... data)
Determines whether the salted hash of the given input equals a known hash
value.
|
static byte[] |
hash(org.bouncycastle.crypto.Digest digest,
int iterations,
Object... data)
Computes the iterated hash of the given data using the given algorithm.
|
static byte[] |
hash(org.bouncycastle.crypto.Digest digest,
Object... data)
Computes the hash of the given data using the given algorithm.
|
static byte[] |
sha1(Object... data)
Produces the SHA-1 hash of the given data.
|
static byte[] |
sha256(Object... data)
Produces the SHA-256 hash of the given data.
|
static byte[] |
sha3(int bitLength,
Object... data)
Produces the SHA-3 hash of the given data.
|
static byte[] |
sha512(Object... data)
Produces the SHA-512 hash of the given data.
|
public static byte[] hash(org.bouncycastle.crypto.Digest digest, Object... data)
// data is a byte array containing raw data to digest final byte[] salt = new RBGNonce(16).generate(); final byte[] hash = HashUtil.hash(new SHA1Digest(), data, salt);
digest
- Hash algorithm.data
- Data to hash. Supported types are byte[]
, CharSequence
,InputStream
, and Resource
.
Character data is processed in the UTF-8
character set; if another character set is desired, the
caller should convert to byte[]
and provide the
resulting bytes.Digest.getDigestSize()
containing
hash output.public static byte[] hash(org.bouncycastle.crypto.Digest digest, int iterations, Object... data)
// data is a byte array containing raw data to digest final byte[] salt = new RBGNonce(16).generate(); final byte[] hash = HashUtil.hash(new SHA1Digest(), 10, data, salt);
digest
- Hash algorithm.iterations
- Number of hash rounds. Must be positive value.data
- Data to hash. Supported types are byte[]
, CharSequence
,InputStream
, and Resource
.
Character data is processed in the UTF-8
character set; if another character set is desired, the
caller should convert to byte[]
and provide the
resulting bytes.Digest.getDigestSize()
containing
hash output.public static boolean compareHash(org.bouncycastle.crypto.Digest digest, byte[] hash, int iterations, Object... data)
digest
- Hash algorithm.hash
- Hash to compare with. 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.iterations
- Number of hash rounds.data
- Data to hash.public static boolean compareHash(org.bouncycastle.crypto.Digest digest, SaltedHash hash, int iterations, boolean saltAfterData, Object... data)
digest
- Hash algorithm.hash
- Salted hash data.iterations
- Number of hash rounds.saltAfterData
- True to apply salt after data, false to apply salt
before data.data
- Data to hash, which should NOT include the salt value.public static byte[] sha1(Object... data)
data
- Data to hash. See hash(Digest, Object...)
for
supported inputs.hash(Digest, Object...)
public static byte[] sha256(Object... data)
data
- Data to hash. See hash(Digest, Object...)
for
supported inputs.hash(Digest, Object...)
public static byte[] sha512(Object... data)
data
- Data to hash. See hash(Digest, Object...)
for
supported inputs.hash(Digest, Object...)
public static byte[] sha3(int bitLength, Object... data)
bitLength
- One of the supported SHA-3 output bit lengths: 224, 256,
384, or 512.data
- Data to hash. See hash(Digest, Object...)
for
supported inputs.bitLength
containing hash output.hash(Digest, Object...)
Copyright © 2016 JBoss by Red Hat. All rights reserved.