Commit 24004afb by zhanghj

V1.1.0--提交md5加密方法

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@20905 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent f79ea094
package com.glsx.common.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
public class MD5Coder {
/**
* md5加密方法
* @param str
* @return
*/
public static String encrypt(String str) {
try {
byte b[] = Encrypter.encryptMD5(str.getBytes("utf-8"));
StringBuffer buf = new StringBuffer();
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = Integer.toHexString(b[n] & 0XFF);
if (stmp.length() == 1)
buf.append("0").append(stmp);
else
buf.append(stmp);
}
return buf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static String MD516(String sourceStr) {
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
try {
md.update(sourceStr.getBytes("GBK"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
result = buf.toString();
result=result.toString().substring(8,24);
} catch (NoSuchAlgorithmException e) {
System.out.println(e);
}
return result;
}
/**
* 获取MD5加密的sign
*
* @param params
* @return
*/
public static String getParamsMD5Sign(Map<Object, Object> params) {
StringBuffer paramsStr = new StringBuffer();
for (Map.Entry<Object, Object> param : params.entrySet()) {
paramsStr.append(param.getKey()).append(param.getValue());
}
return MD5Coder.encrypt(paramsStr.toString()).toUpperCase();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!