当前位置:网站首页>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));
}
}
边栏推荐
- From repvgg to mobileone, including mobileone code
- New intersectionobserver usage notes
- 面试题 01.08. 零矩阵
- 《命令行上的数据科学第二版》校对活动重新启动
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- 能源势动:电力行业的碳中和该如何实现?
- Play with grpc - go deep into concepts and principles
- Force buckle_ Palindrome number
- odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
- 可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
猜你喜欢
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
Bizchart+slider to realize grouping histogram
能源势动:电力行业的碳中和该如何实现?
TLA+ 入门教程(1):形式化方法简介
卷积神经网络模型之——LeNet网络结构与代码实现
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
抖音实战~评论数量同步更新
Scala download and configuration
随机推荐
[acwing] solution of the 58th weekly match
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
BigFilter全局交易防重组件的介绍与应用
短视频系统源码,点击屏幕空白处键盘不自动收起
Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
[advanced C language] array & pointer & array written test questions
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
将QA引入软件开发生命周期是工程师要遵循的最佳实践
Concurrent network modular reading notes transfer
Force buckle 3_ 383. Ransom letter
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
力扣2_1480. 一维数组的动态和
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
Mysql root 账号如何重置密码
使用 BlocConsumer 同时构建响应式组件和监听状态
并发优化总结
常用的开源无代码测试工具