Here you can find the source of digest(String strSrc, String encName)
public static String digest(String strSrc, String encName)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String digest(String strSrc, String encName) { MessageDigest md = null;//w ww .java2 s . c om String strDes = null; byte[] bt = strSrc.getBytes(); try { if (encName == null || encName.equals("")) { encName = "MD5"; } md = MessageDigest.getInstance(encName); md.update(bt); strDes = bytesToHexString(md.digest()); // to HexString } catch (NoSuchAlgorithmException e) { return null; } return strDes; } public static String bytesToHexString(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); } }