Java Utililty Methods Hash Calculate

List of utility methods to do Hash Calculate

Description

The list of methods to do Hash Calculate are organized into topic(s).

Method

StringgetHashOf(String s)
get Hash Of
MessageDigest md = MessageDigest.getInstance("SHA-256");
s += "TTM";
md.update(s.getBytes());
return byteArrayToHexString(md.digest());
StringgetHashString()
get Hash String
long hashLong;
synchronized (hashGenerator) {
    hashLong = hashGenerator.nextLong() & 0x7FFFFFFFFFFFFFFFL;
return Long.toHexString(hashLong);
StringgetHashString(byte[] data)
get Hash String
return stringFormat(getHash(data));
StringgetHashString(String password, String salt)
get Hash String
return bin2hex(getHash(iterations, createPasswordKey(password, salt), hex2bin(salt)));
StringgetHashWithSalt(String input, String algorithm, String salt)
This method hashes a string according to the desired message digest algorithm.
MessageDigest digest = MessageDigest.getInstance(algorithm);
digest.reset();
digest.update(salt.getBytes("UTF-8"));
byte[] bytes = digest.digest(input.getBytes("UTF-8"));
for (int i = 0; i < ITER; i++) {
    digest.reset();
    bytes = digest.digest(bytes);
return new BigInteger(1, bytes).toString(16);
inthash()
Optimized implementation of #hash(int[]) with 0 args.
return 1;
inthash(Boolean value)
hash
return value ? 1231 : 1237;
inthash(boolean value, int seed)
Alters the given seed with the hash code value computed from the given value.
return seed * PRIME_NUMBER + (value ? 1231 : 1237);
inthash(boolean[] array)
hash
if (array.length == 4) {
    if (!array[0] && !array[1] && !array[2] && !array[3]) {
        return 0;
    return ((array[0] ? 1 : 0) << 3) + ((array[1] ? 1 : 0) << 2) + ((array[2] ? 1 : 0) << 1)
            + (array[3] ? 1 : 0);
int n = 0;
...
inthash(byte x)
hash
return x;