Here you can find the source of md5(String message)
public static String md5(String message)
//package com.java2s; /**//from ww w . j a v a2 s . c o m * JMongo is a mongodb driver writtern in java. * Copyright (C) 2010 Xiaohu Huang * * JMongo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JMongo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JMongo. If not, see <http://www.gnu.org/licenses/>. */ import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String md5(String message) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] buffer = message.getBytes("UTF-8"); digest.update(buffer); return encodeHex(digest.digest()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } } public static String encodeHex(byte[] data) { int l = data.length; char[] out = new char[l << 1]; // two characters form the hex value. for (int i = 0, j = 0; i < l; i++) { out[j++] = DIGITS_LOWER[(0xF0 & data[i]) >>> 4]; out[j++] = DIGITS_LOWER[0x0F & data[i]]; } return new String(out); } }