Here you can find the source of getHash(String phrase, String algorithm)
public static String getHash(String phrase, String algorithm)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String getHash(String phrase, String algorithm) { return getHexString(getByteHash(phrase, algorithm)); }/*from w ww.j ava 2 s . c om*/ private static String getHexString(byte[] bytes) { StringBuilder s = new StringBuilder(); for (byte aByte : bytes) { int higherPart = ((aByte >> 4) & 0xf) << 4; int lowerPart = aByte & 0xf; if (higherPart == 0) { s.append('0'); } s.append(Integer.toHexString(higherPart | lowerPart)); } return s.toString(); } private static byte[] getByteHash(String phrase, String algorithm) { try { MessageDigest md = MessageDigest.getInstance(algorithm); md.update(phrase.getBytes()); return md.digest(); } catch (NoSuchAlgorithmException e) { return null; } } }