Here you can find the source of md5(String s)
public static String md5(String s)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final String MD5 = "MD5"; public static String md5(String s) { return encrypt(s, MD5); }// w w w .j av a 2s . c om public static String encrypt(String s, String algorithm) { byte[] unencodedPassword = s.getBytes(); MessageDigest md = null; // first create an instance, given the provider try { md = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } md.reset(); // call the update method one or more times // (useful when you don't know the size of your data, eg. stream) md.update(unencodedPassword); // now calculate the hash byte[] bytes = md.digest(); StringBuffer result = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { if (((int) bytes[i] & 0xff) < 0x10) { result.append("0"); } result.append(Long.toString((int) bytes[i] & 0xff, 16)); } return result.toString(); } }