Here you can find the source of hash(String s, String algorithm)
private static String hash(String s, String algorithm)
//package com.java2s; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static String hash(String s, String algorithm) { String result = s;//ww w .j a v a 2 s . c o m try { MessageDigest digest = MessageDigest.getInstance(algorithm); byte[] bytes = digest.digest(s.getBytes()); BigInteger biggie = new BigInteger(1, bytes); result = String .format("%0" + (bytes.length << 1) + "x", biggie); } catch (NoSuchAlgorithmException e) { // No way... } return result; } }