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

StringgetHash(String password, String bsalt)
From a password, a number of iterations and a provided salt, returns the corresponding digest
byte[] salt = base64ToByte(bsalt);
byte[] input = calculateHash(password, salt);
return byteToBase64(input);
StringgetHash(String password, String salt)
Gets a salted hash code.
try {
    MessageDigest messageDigest = null;
    messageDigest = MessageDigest.getInstance(SHA_512);
    messageDigest.reset();
    messageDigest.update(salt.getBytes("UTF-8"));
    messageDigest.update(password.getBytes("UTF-8"));
    byte[] input = messageDigest.digest();
    for (int i = 0; i < 1000; i++) {
...
StringgetHash(String password, String salt)
Calculates the hash of a password and salt using SHA-256.
String salted = salt + password;
String hashed = salted;
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(salted.getBytes());
    hashed = encodeHex(md.digest(), 64);
} catch (Exception ex) {
    hashed = null;
...
StringgetHash(String phrase, String algorithm)
get Hash
return getHexString(getByteHash(phrase, algorithm));
StringgetHash(String s)
get Hash
try {
    MessageDigest algorithm = MessageDigest.getInstance("MD5");
    algorithm.reset();
    algorithm.update(s.getBytes());
    byte[] hashDigest = algorithm.digest();
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < hashDigest.length; i++) {
        String hex = Integer.toHexString(0xFF & hashDigest[i]);
...
StringgetHash(String str, String algorithm)
Return the hezadecimal representation of the string digest given the specified algorithm.
MessageDigest md = MessageDigest.getInstance(algorithm);
md.update(str.getBytes());
byte byteData[] = md.digest();
StringBuilder hexString = new StringBuilder();
for (int i = 0; i < byteData.length; i++) {
    String hex = Integer.toHexString(0xff & byteData[i]);
    if (hex.length() == 1) {
        hexString.append('0');
...
byte[]getHash(String strDate)
get Hash
byte[] strDateByte = strDate.getBytes();
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(strDateByte, 0, strDateByte.length);
return md.digest();
char[]getHash(String text)
get Hash
byte[] data = text.getBytes("utf-8");
MessageDigest md = MessageDigest.getInstance("MD5");
for (byte b : data) {
    md.update(b);
byte[] digest = md.digest();
char[] hash = new char[digest.length];
int index = 0;
...
StringgetHash(String valueToHash)
get Hash
MessageDigest digest;
try {
    digest = java.security.MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
    return null;
digest.update(valueToHash.getBytes());
byte messageDigest[] = digest.digest();
...
StringgetHash(String var)
get Hash
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    byte[] varbytes = var.getBytes("UTF-8");
    byte[] result = md.digest(varbytes);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < result.length; ++i) {
        sb.append(Integer.toHexString(0xFF & result[i]));
    String hash = sb.toString();
    return hash;
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return null;