Here you can find the source of md5(String str)
public final static String md5(String str)
//package com.java2s; /**/*w w w . j av a2 s . c o m*/ * Core-level framework class: String and Date basic utility methods. * <br><br> * Encapsulates utility methods for everyday programming tasks * with Strings, Dates and other common stuff. * <br> * Creation date: 18/09/2003<br> * Last Update: 18/09/2003<br> * (c) 2003 Martin Cordova<br> * This code is released under the LGPL license<br> * @author Martin Cordova (some code written by Carlos Pineda) */ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public final static String md5(String str) { if (str == null || str.length() == 0) { return ""; } else { StringBuffer sb = new StringBuffer(); try { MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(str.getBytes()); byte[] md5 = algorithm.digest(); String singleByteHex = ""; for (int i = 0; i < md5.length; i++) { singleByteHex = Integer.toHexString(0xFF & md5[i]); if (singleByteHex.length() == 1) { sb.append("0"); } sb.append(singleByteHex.toUpperCase()); } } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } return sb.toString(); } } }