当前位置:网站首页>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));
}
}
边栏推荐
- [advanced C language] array & pointer & array written test questions
- 微服务--开篇
- 2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
- LOGO特训营 第三节 首字母创意手法
- MySQL storage data encryption
- 傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
- DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
- 常用的开源无代码测试工具
- NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
- ACM multimedia 2022 | counterfactual measurement and elimination of social prejudice in visual language pre training model
猜你喜欢

抖音实战~评论数量同步更新

A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo

湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章

卷积神经网络模型之——LeNet网络结构与代码实现

Concurrent optimization summary
![[Yugong series] go teaching course 003-ide installation and basic use in July 2022](/img/65/b36ca239e06a67c01d1eb0b4648f71.png)
[Yugong series] go teaching course 003-ide installation and basic use in July 2022

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

虚拟人产业面临的挑战

Domestic database chaos

Scala下载和配置
随机推荐
抖音实战~评论数量同步更新
The use of complex numbers in number theory and geometry - Cao Zexian
LOGO特训营 第三节 首字母创意手法
Domestic database chaos
常用的开源无代码测试工具
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe to open an account online
How to reset the password of MySQL root account
Implementation rules for archiving assessment materials of robot related courses 2022 version
HDU - 1078 fatmouse and cheese (memory search DP)
HDU - 2859 Phalanx(DP)
BigFilter全局交易防重组件的介绍与应用
如何实现轻松管理1500万员工?
Spatiotemporal prediction 3-graph transformer
【Acwing】第58场周赛 题解
Why do you have to be familiar with industry and enterprise business when doing Bi development?
Representation of confidence interval
El tree combined with El table, tree adding and modifying operations
我在linux里面 通过调用odspcmd 查询数据库信息 怎么静默输出 就是只输出值 不要这个
面试必备 LeetCode 链表算法题汇总,全程干货!