Here you can find the source of md5(String str)
public static String md5(String str)
//package com.java2s; //License from project: LGPL import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//from w w w.j a v a 2 s . c o m * @return 32-character string. */ public static String md5(String str) { MessageDigest algorithm; try { algorithm = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("No M5 messagedigest!", e); } byte[] defaultBytes = str.getBytes(); algorithm.reset(); algorithm.update(defaultBytes); byte messageDigest[] = algorithm.digest(); StringBuilder hexString = new StringBuilder(); for (byte aMessageDigest : messageDigest) { String hex = Integer.toHexString(0xFF & aMessageDigest); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } return hexString.toString(); } }