Here you can find the source of getHash(String password, String salt)
Parameter | Description |
---|---|
password | - password to hash |
salt | - salt associated with user |
public static String getHash(String password, String salt)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; import java.security.MessageDigest; public class Main { /**//from w w w. j a v a 2s . co m * Calculates the hash of a password and salt using SHA-256. * * @param password * - password to hash * @param salt * - salt associated with user * @return hashed password, or null if unable to hash */ public static String getHash(String password, String salt) { 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; } return hashed; } /** * Returns the hex encoding of a byte array. * * @param bytes * - byte array to encode * @param length * - desired length of encoding * @return hex encoded byte array */ public static String encodeHex(byte[] bytes, int length) { BigInteger bigint = new BigInteger(1, bytes); String hex = String.format("%0" + length + "X", bigint); assert hex.length() == length; return hex; } }