Here you can find the source of MD5Encode(String s)
Parameter | Description |
---|---|
s | String to encode |
public static String MD5Encode(String s)
//package com.java2s; public class Main { /**/*from w ww .j a v a 2 s.c o m*/ * Produces MD5 hash for the specified string * * @param s String to encode * @return MD5 hash */ public static String MD5Encode(String s) { try { final java.security.MessageDigest md = java.security.MessageDigest .getInstance("MD5"); return bytesToHex(md.digest(s.getBytes())); } catch (Exception e) { return ""; } } public static String bytesToHex(byte[] buf) { final StringBuilder b = new StringBuilder(buf.length * 2); for (int i = 0; i < buf.length; i++) { final int cell = (int) (buf[i] & 0xFF); if (cell < 16) { b.append("0"); } b.append(Integer.toString(cell, 16)); } return b.toString(); } }