当前位置:网站首页>md5工具类
md5工具类
2022-07-04 22:00:00 【wgq18586361686】
package com.example.springboottemplate.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* MD5加密工具类
*/
public class MD5Util {
private static final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
/**
* MD5加密 (大写)
*
* @param inStr
* @return 32byte MD5 Value
*/
public static String MD5(String inStr) {
byte[] inStrBytes = inStr.getBytes();
try {
MessageDigest MD = MessageDigest.getInstance("MD5");
MD.update(inStrBytes);
byte[] mdByte = MD.digest();
char[] str = new char[mdByte.length * 2];
int k = 0;
for (int i = 0; i < mdByte.length; i++) {
byte temp = mdByte[i];
str[k++] = hexDigits[temp >>> 4 & 0xf];
str[k++] = hexDigits[temp & 0xf];
}
return new String(str);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
/**
* MD5加密(小写)
*
* @param source
* @return
*/
public static String md5(String source) {
StringBuffer sb = new StringBuffer(32);
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] array = md.digest(source.getBytes("utf-8"));
for (int i = 0; i < array.length; i++) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
public static void main(String[] args) {
String str ="123";
System.out.println(MD5Util.MD5(str));
System.out.println(MD5Util.md5(str));
}
}
边栏推荐
- Use blocconsumer to build responsive components and monitor status at the same time
- 服装企业为什么要谈信息化?
- New intersectionobserver usage notes
- Why do you have to be familiar with industry and enterprise business when doing Bi development?
- i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
- 力扣_回文数
- Concurrent network modular reading notes transfer
- 我在linux里面 通过调用odspcmd 查询数据库信息 怎么静默输出 就是只输出值 不要这个
- From repvgg to mobileone, including mobileone code
- 微服务--开篇
猜你喜欢

Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei

DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效

TLA+ 入门教程(1):形式化方法简介

【Acwing】第58场周赛 题解

迷失在Mysql的锁世界

PMO:比较25种分子优化方法的样本效率

Kdd2022 | what features are effective for interaction?

Energy momentum: how to achieve carbon neutralization in the power industry?

TCP protocol three times handshake process

30余家机构联合发起数字藏品行业倡议,未来会如何前进?
随机推荐
php短视频源码,点赞时会有大拇指动画飘起
Machine learning notes mutual information
UML图记忆技巧
Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
Kdd2022 | what features are effective for interaction?
复数在数论、几何中的用途 - 曹则贤
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
i. Mx6ull driver development | 24 - platform based driver model lights LED
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
LOGO特训营 第一节 鉴别Logo与Logo设计思路
Domestic database chaos
Energy momentum: how to achieve carbon neutralization in the power industry?
How to transfer to software testing, one of the high paying jobs in the Internet? (software testing learning roadmap attached)
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
国产数据库乱象
Postgresqlql advanced skills pivot table
嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
大厂的广告系统升级,怎能少了大模型的身影
283. 移动零-c与语言辅助数组法