Here you can find the source of md5(String data)
public static String md5(String data)
//package com.java2s; /******************************************************************************* * Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * Copyright (c) 2011- kotemaru@kotemaru.org ******************************************************************************/ import java.security.MessageDigest; public class Main { private final static String MD = "MD5"; private final static String UTF8 = "UTF-8"; private final static char[] HEX_MAP = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String md5(String data) { try {/*from w w w . j a v a 2 s .c o m*/ MessageDigest md = MessageDigest.getInstance(MD); md.update(data.getBytes(UTF8)); return encodeHex(md.digest()); } catch (Exception e) { throw new RuntimeException(e); } } public static String encodeHex(String str) { try { return encodeHex(str.getBytes(UTF8)); } catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } } public static String encodeHex(byte[] bytes) { char[] buff = new char[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { int h0 = (bytes[i] >> 4) & 0x0f; int h1 = bytes[i] & 0x0f; buff[i * 2] = HEX_MAP[h0]; buff[i * 2 + 1] = HEX_MAP[h1]; } return new String(buff); } }