当前位置:网站首页>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));
}
}
边栏推荐
- Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
- 嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
- 力扣3_383. 赎金信
- Domestic database chaos
- 面试题 01.08. 零矩阵
- NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
- Why should garment enterprises talk about informatization?
- Machine learning notes mutual information
猜你喜欢

UML图记忆技巧

i. Mx6ull driver development | 24 - platform based driver model lights LED

达梦数据凭什么被称为国产数据库“第一股”?

力扣98:验证二叉搜索树

30余家机构联合发起数字藏品行业倡议,未来会如何前进?

Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry

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

迷失在Mysql的锁世界

复数在数论、几何中的用途 - 曹则贤
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
随机推荐
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
Use blocconsumer to build responsive components and monitor status at the same time
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
[advanced C language] array & pointer & array written test questions
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
大厂的广告系统升级,怎能少了大模型的身影
机器学习笔记 - 互信息Mutual Information
Convolutional neural network model -- lenet network structure and code implementation
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
Relational database
不同环境相同配置项的内容如何diff差异?
删库不必跑路!详解 MySQL 数据恢复
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
Energy momentum: how to achieve carbon neutralization in the power industry?
阿里推出新品牌“瓴羊”,致力成为“数字化领头羊”
傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
服务线上治理
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
Which securities company is better to open an account? Is online account opening safe