Here you can find the source of md5(String s)
public static String md5(String s)
//package com.java2s; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String md5(String s) { /*/* ww w.j a v a 2 s. co m*/ * try { // Create MD5 Hash MessageDigest digest = * java.security.MessageDigest.getInstance("MD5"); * digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); * // Create Hex String StringBuffer hexString = new StringBuffer(); for * (int i=0; i<messageDigest.length; i++) * hexString.append(Integer.toHexString(0xFF & messageDigest[i])); * return hexString.toString(); } catch (NoSuchAlgorithmException e) { * e.printStackTrace(); } return ""; */ MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); digest.update(s.getBytes(), 0, s.length()); String hash = new BigInteger(1, digest.digest()).toString(16); if (hash.length() % 2 != 0) { return "0" + hash; } return hash; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; } }