Commit 04f796bb authored by zhangyong's avatar zhangyong

1

parent 4ae91871
...@@ -8,11 +8,15 @@ import java.io.PrintWriter; ...@@ -8,11 +8,15 @@ import java.io.PrintWriter;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -1016,4 +1020,45 @@ public class StringUtil { ...@@ -1016,4 +1020,45 @@ public class StringUtil {
return ""; return "";
} }
/**
*
* @Title: doMD5Sign
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param map
* @param: @return
* @return: String
* @throws
*/
public static String doMD5Sign(Map<String, String> map){
Map<String, String> compMap = new TreeMap<String, String>(
new Comparator<String>() {
public int compare(String obj1, String obj2) {
return obj1.compareTo(obj2);
}
});
for(Entry<String, String> entry : map.entrySet()){
compMap.put(entry.getKey(), entry.getValue());
}
StringBuffer sb = new StringBuffer();
for(Entry<String, String> entry : compMap.entrySet()){
sb.append("&");
sb.append(entry.getKey());
sb.append("=");
sb.append(entry.getValue());
}
String s = sb.toString().substring(1);
byte[] secretBytes = null;
try {
secretBytes = MessageDigest.getInstance("MD5").digest(s.getBytes());
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sign = Hex.encodeHexString(secretBytes).toUpperCase();
return sign;
}
public static String getRandom(int num){
return String.valueOf(Math.random()).substring(2, 2+num);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment