Here you can find the source of digest(String orgin, String algorithm)
public static String digest(String orgin, String algorithm)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; public class Main { public static String digest(String orgin, String algorithm) { try {/*from www. ja v a 2 s . c o m*/ byte[] strTemp = orgin.getBytes("utf-8"); MessageDigest mdTemp = MessageDigest.getInstance(algorithm); mdTemp.update(strTemp); byte[] md = mdTemp.digest(); return bytes2hex(md); } catch (Exception e) { return null; } } public static String bytes2hex(byte[] bts) { char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; int j = bts.length; char str[] = new char[j * 2]; int k = 0; for (int i = 0; i < j; i++) { byte byte0 = bts[i]; str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); } }