当前位置:网站首页>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));
}
}
边栏推荐
- 面试题 01.01. 判定字符是否唯一
- Apachecn translation, proofreading, note sorting activity progress announcement 2022.7
- Flask 上下文详解
- Convolutional neural network model -- lenet network structure and code implementation
- Easy to use app recommendation: scan QR code, scan barcode and view history
- TCP协议三次握手过程
- WebGIS框架---kalrry
- Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
- Energy momentum: how to achieve carbon neutralization in the power industry?
- 面试必备 LeetCode 链表算法题汇总,全程干货!
猜你喜欢
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
É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)
PMO:比较25种分子优化方法的样本效率
Concurrent optimization summary
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Tiktok actual combat ~ the number of comments is updated synchronously
LOGO特训营 第五节 字体结构与设计常用技法
抖音实战~评论数量同步更新
The use of complex numbers in number theory and geometry - Cao Zexian
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
随机推荐
Easy to use app recommendation: scan QR code, scan barcode and view history
Postgresqlql advanced skills pivot table
高中物理:直线运动
抖音实战~评论数量同步更新
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
力扣98:验证二叉搜索树
大厂的广告系统升级,怎能少了大模型的身影
Kdd2022 | what features are effective for interaction?
i. Mx6ull driver development | 24 - platform based driver model lights LED
PMO:比较25种分子优化方法的样本效率
Domestic database chaos
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
Machine learning notes mutual information
KDD2022 | 什么特征进行交互才是有效的?
PostgreSQL JOIN实践及原理
HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
保证接口数据安全的10种方案
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
Sqlserver encrypts and decrypts data
Implementation rules for archiving assessment materials of robot related courses 2022 version