当前位置:网站首页>MD5 tool class
MD5 tool class
2022-07-04 22:30:00 【wgq18586361686】
package com.example.springboottemplate.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* MD5 Encryption utility class
*/
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 encryption ( Capitalization )
*
* @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 encryption ( A lowercase letter )
*
* @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));
}
}
边栏推荐
- PMO:比较25种分子优化方法的样本效率
- 智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
- 现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
- Practice and principle of PostgreSQL join
- 30余家机构联合发起数字藏品行业倡议,未来会如何前进?
- 大厂的广告系统升级,怎能少了大模型的身影
- Telephone encryption, middle 4 is replaced by * * * *
- Jvm-Sandbox-Repeater的部署
- 不同环境相同配置项的内容如何diff差异?
- Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
猜你喜欢

Logo Camp d'entraînement section 3 techniques créatives initiales

使用 BlocConsumer 同时构建响应式组件和监听状态

虚拟人产业面临的挑战

Concurrent network modular reading notes transfer

卷积神经网络模型之——LeNet网络结构与代码实现

凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer

能源势动:电力行业的碳中和该如何实现?

Domestic database chaos

湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章

B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
随机推荐
力扣_回文数
Easy to use app recommendation: scan QR code, scan barcode and view history
Domestic database chaos
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Why is Dameng data called the "first share" of domestic databases?
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
抖音实战~评论数量同步更新
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
【C语言进阶篇】数组&&指针&&数组笔试题
Convolutional neural network model -- lenet network structure and code implementation
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
Interview question 01.01 Determine whether the character is unique
Interview question 01.08 Zero matrix
Service online governance
阿里推出新品牌“瓴羊”,致力成为“数字化领头羊”
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
力扣2_1480. 一维数组的动态和
Telephone encryption, middle 4 is replaced by * * * *
SPSS安装激活教程(包含网盘链接)