当前位置:网站首页>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));
}
}
边栏推荐
- Cadre WebGIS - kalrry
- Service online governance
- 力扣_回文数
- LOGO特训营 第一节 鉴别Logo与Logo设计思路
- 制作条形码的手机App推荐
- Why do you have to be familiar with industry and enterprise business when doing Bi development?
- Concurrent network modular reading notes transfer
- 使用 BlocConsumer 同时构建响应式组件和监听状态
- Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
- Common open source codeless testing tools
猜你喜欢
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
【C语言进阶篇】数组&&指针&&数组笔试题
嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
Convolutional neural network model -- lenet network structure and code implementation
抖音实战~评论数量同步更新
傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
close系统调用分析-性能优化
TLA+ 入门教程(1):形式化方法简介
并发网络模块化 读书笔记转
随机推荐
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?
HBuilder X 常用的快捷键
VIM from dislike to dependence (23) -- the last gossip
# 2156. 查找给定哈希值的子串-后序遍历
Interview question 01.08 Zero matrix
From repvgg to mobileone, including mobileone code
Detailed explanation of flask context
力扣2_1480. 一维数组的动态和
Convolutional neural network model -- lenet network structure and code implementation
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
PMO:比较25种分子优化方法的样本效率
Representation of confidence interval
大厂的广告系统升级,怎能少了大模型的身影
[advanced C language] array & pointer & array written test questions
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
What is business intelligence (BI), just look at this article is enough
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
短视频系统源码,点击屏幕空白处键盘不自动收起
How can the advertising system of large factories be upgraded without the presence of large models