Here you can find the source of md5(String plainText)
Parameter | Description |
---|---|
plainText | a parameter |
public static String md5(String plainText)
//package com.java2s; /**/*from w w w .j a v a 2 s .co m*/ * License * * Licensed under the GNU GPL v3 * http://www.gnu.org/licenses/gpl.html * */ import java.security.MessageDigest; public class Main { /** * MD5 * * @param plainText * @return */ public static String md5(String plainText) { return md5(plainText.getBytes()); } public static String md5(byte[] plainText) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(plainText); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (Exception e) { throw new RuntimeException(e); } return result; } }