工具类--MD5Utils
2024-09-04 04:10:14
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;
} }
最新文章
- java分页问题
- E1、T1链路
- Elasticsearch Span Query跨度查询
- appid账号创建及A D-U-M-S码创建
- ***PHP Notice: Undefined index: ..问题的解决方法
- 利用Android手机里的摄像头进行拍照
- SQL Server 触发器:表的特定字段更新时,触发Update触发器
- 全国计算机等级考试二级教程-C语言程序设计_第7章_函数
- python 调用图灵机器人api实现简单的人机交互
- Python学习笔记16:标准库多线程(threading包裹)
- ColorMatrixFilter色彩矩阵滤镜(as3)
- RHCE6.4 rpm 安装gcc
- 小试ImageMagik——使用篇
- CSS 火焰?不在话下
- Centos7安装并配置mysql5.6
- leetcode 第4题 Median of Two Sorted Arrays
- golang中发送http请求的几种常见情况
- MSP MCU I2C入门指南
- .NET Core 对象到字节数组的序列化和反序列化
- [转]触发窗体事件(例如按Esc关闭窗体),WinForm
热门文章
- 老板让我十分钟上手nx-admin
- JavaScript--字符串与JSON对象相互转换
- leetcode上的一些分治算法
- webpack构建缓存机制-hash介绍
- 大数据学习之BigData常用算法和数据结构
- how to convert from hex to disasm
- 泛微oa系统com.eweaver.base.DataAction文件sql参数sql注入
- LINUX 安装PHP GD库遇到的坑
- 第一周复习一 ( HTML表单form)
- jmeter 后台运行 setsid bin/jmeter -n -t .jmx文件 -l .jtl文件