public class MD5Utils {

    private static final String[] HEX_DIGITS = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; private static String byteArrayToHexString(byte b[]) {
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
resultSb.append(byteToHexString(b[i]));
} return resultSb.toString();
} private static String byteToHexString(byte b) {
int n = b;
if (n < 0) {
n += 256;
}
int d1 = n / 16;
int d2 = n % 16;
return HEX_DIGITS[d1] + HEX_DIGITS[d2];
} /**
* 字符串MD5加密
* @param str
* @return
*/
public static String encode(String str) throws Exception {
if (StringUtils.hasText(str)) {
return DigestUtils.md5DigestAsHex(str.getBytes());
}
return null;
} public static String md5Encode(String origin, String charsetname) {
String resultString = null;
try {
resultString = new String(origin);
MessageDigest md = MessageDigest.getInstance("MD5");
if (charsetname == null || "".equals(charsetname)) {
resultString = byteArrayToHexString(md.digest(resultString
.getBytes()));
} else {
resultString = byteArrayToHexString(md.digest(resultString
.getBytes(charsetname)));
}
} catch (Exception exception) {
}
return resultString;
} }

最新文章

  1. java分页问题
  2. E1、T1链路
  3. Elasticsearch Span Query跨度查询
  4. appid账号创建及A D-U-M-S码创建
  5. ***PHP Notice: Undefined index: ..问题的解决方法
  6. 利用Android手机里的摄像头进行拍照
  7. SQL Server 触发器:表的特定字段更新时,触发Update触发器
  8. 全国计算机等级考试二级教程-C语言程序设计_第7章_函数
  9. python 调用图灵机器人api实现简单的人机交互
  10. Python学习笔记16:标准库多线程(threading包裹)
  11. ColorMatrixFilter色彩矩阵滤镜(as3)
  12. RHCE6.4 rpm 安装gcc
  13. 小试ImageMagik——使用篇
  14. CSS 火焰?不在话下
  15. Centos7安装并配置mysql5.6
  16. leetcode 第4题 Median of Two Sorted Arrays
  17. golang中发送http请求的几种常见情况
  18. MSP MCU I2C入门指南
  19. .NET Core 对象到字节数组的序列化和反序列化
  20. [转]触发窗体事件(例如按Esc关闭窗体),WinForm

热门文章

  1. 老板让我十分钟上手nx-admin
  2. JavaScript--字符串与JSON对象相互转换
  3. leetcode上的一些分治算法
  4. webpack构建缓存机制-hash介绍
  5. 大数据学习之BigData常用算法和数据结构
  6. how to convert from hex to disasm
  7. 泛微oa系统com.eweaver.base.DataAction文件sql参数sql注入
  8. LINUX 安装PHP GD库遇到的坑
  9. 第一周复习一 ( HTML表单form)
  10. jmeter 后台运行 setsid bin/jmeter -n -t .jmx文件 -l .jtl文件