public class Md5Util { /** * md5加密的方法 * @param text * @return */ public static String encode(String text){ try { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] result = digest.digest(text.getBytes()); StringBuilder sb = new StringBuilder(); for(byte b : result){ int number = b&0xff; String hex = Integer.toHexString(number); if(hex.length()==1){ sb.append("0"); } sb.append(hex); } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return ""; } } }
原文:http://blog.csdn.net/u014600432/article/details/41380999