Here you can find the source of md5Signature(TreeMap
public static String md5Signature(TreeMap<String, String> params, String secret)
//package com.java2s; import java.security.MessageDigest; import java.util.Iterator; import java.util.Map; import java.util.TreeMap; public class Main { public static String md5Signature(TreeMap<String, String> params, String secret) {/*from ww w. j a v a 2 s .c o m*/ String result = null; StringBuffer orgin = getBeforeSign(params, new StringBuffer(secret)); if (orgin == null) return result; orgin.append(secret); try { MessageDigest md = MessageDigest.getInstance("MD5"); result = byte2hex(md.digest(orgin.toString().getBytes("utf-8"))); } catch (Exception e) { throw new java.lang.RuntimeException("sign error !"); } return result; } private static StringBuffer getBeforeSign( TreeMap<String, String> params, StringBuffer orgin) { if (params == null) return null; Map<String, String> treeMap = new TreeMap<String, String>(); treeMap.putAll(params); Iterator<String> iter = treeMap.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); orgin.append(name).append(params.get(name)); } return orgin; } private static String byte2hex(byte[] b) { StringBuffer hs = new StringBuffer(); String stmp = ""; for (int n = 0; n < b.length; n++) { stmp = (java.lang.Integer.toHexString(b[n] & 0XFF)); if (stmp.length() == 1) { hs.append("0").append(stmp); } else { hs.append(stmp); } } return hs.toString().toUpperCase(); } }