用eclipse 将内容加密运行正常
在服务器上跑就出错 问题:eclipse上设置了默认项目编码为utf8,服务器上没设,设置完服务器上就字符编码就能正常运行
md5加密写法
/**
* 取得字符串的摘要信息
* @param input
* @return
*/
public static String getMd5(String input){
byte[] out = null;
try {
MessageDigest md = MessageDigest.getInstance(“MD5”);
md.update(input.getBytes(“UTF-8”));
out = md.digest();
} catch (NoSuchAlgorithmException e) {
return null;
} catch (UnsupportedEncodingException e) {
return null;
}
return toHexString(out);
}
/**
* 转换成16进制
* @param out
* @return
*/
private static String toHexString(byte[] out) {
StringBuffer buf = new StringBuffer();
for(byte b:out){
buf.append(String.format("%02X", b));
}
return buf.toString();
}