Here you can find the source of md5(String text)
Parameter | Description |
---|---|
text | String |
public static String md5(String text)
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**/* w ww. j a va 2 s.c om*/ * returning a MD5 hash string * * @param text String * @return String */ public static String md5(String text) { try { if (text == null) { return ""; } byte[] digest = MessageDigest.getInstance("MD5").digest(text.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < digest.length; i++) { sb.append(Integer.toString((digest[i] & 0xf0) >> 4, 16)); sb.append(Integer.toString(digest[i] & 0x0f, 16)); } return sb.toString(); } catch (NoSuchAlgorithmException nsae) { return null; } } }