Here you can find the source of md5Hex(String s)
Parameter | Description |
---|---|
s | The string to md5sum |
public static String md5Hex(String s)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; public class Main { /**/*from w w w .jav a 2 s . c om*/ * Generates the hex md5sum of a string. * @param s The string to md5sum * @return The 32-character hex md5sum */ public static String md5Hex(String s) { StringBuffer sb = new StringBuffer(); MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (Exception e) { return null; } md.update(s.getBytes()); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { int b = digest[i] & 0xff; String hex = Integer.toHexString(b); if (hex.length() == 1) sb.append("0"); sb.append(hex); } return sb.toString(); } }