当前位置:网站首页>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));
}
}
边栏推荐
- NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
- HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
- 服装企业为什么要谈信息化?
- 如何实现轻松管理1500万员工?
- Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
- close系统调用分析-性能优化
- Bookmark
- Play with grpc - go deep into concepts and principles
- Bizchart+slider to realize grouping histogram
- Concurrent optimization summary
猜你喜欢
Convolutional neural network model -- lenet network structure and code implementation
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
国产数据库乱象
并发优化总结
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
BigFilter全局交易防重组件的介绍与应用
Machine learning notes mutual information
【C语言进阶篇】数组&&指针&&数组笔试题
随机推荐
Alibaba launched a new brand "Lingyang" and is committed to becoming a "digital leader"
ACM multimedia 2022 | counterfactual measurement and elimination of social prejudice in visual language pre training model
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
Energy momentum: how to achieve carbon neutralization in the power industry?
机器学习笔记 - 互信息Mutual Information
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
The use of complex numbers in number theory and geometry - Cao Zexian
PostgreSQL JOIN实践及原理
Why should garment enterprises talk about informatization?
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
Solana链上应用Crema因黑客攻击停运
# 2156. 查找给定哈希值的子串-后序遍历
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
力扣2_1480. 一维数组的动态和
力扣98:验证二叉搜索树
php短视频源码,点赞时会有大拇指动画飘起
The proofreading activity of data science on the command line second edition was restarted
大厂的广告系统升级,怎能少了大模型的身影