当前位置:网站首页>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));
}
}
边栏推荐
- 傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
- PHP short video source code, thumb animation will float when you like it
- idea中pom.xml依赖无法导入
- Cadre WebGIS - kalrry
- LOGO特训营 第四节 字体设计的重要性
- The use of complex numbers in number theory and geometry - Cao Zexian
- 可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
- HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
- Telephone encryption, middle 4 is replaced by * * * *
- 【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
猜你喜欢
TLA+ 入门教程(1):形式化方法简介
抖音实战~评论数量同步更新
TCP protocol three times handshake process
The use of complex numbers in number theory and geometry - Cao Zexian
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
Introduction and application of bigfilter global transaction anti duplication component
将QA引入软件开发生命周期是工程师要遵循的最佳实践
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
随机推荐
Introduction and application of bigfilter global transaction anti duplication component
Machine learning notes mutual information
复数在数论、几何中的用途 - 曹则贤
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
Introducing QA into the software development lifecycle is the best practice that engineers should follow
微服务--开篇
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe to open an account online
MySQL存储数据加密
Logo special training camp section 1 Identification logo and logo design ideas
【烹饪记录】--- 青椒炒千张
Force buckle 3_ 383. Ransom letter
服装企业为什么要谈信息化?
Practice and principle of PostgreSQL join
KDD2022 | 什么特征进行交互才是有效的?
国产数据库乱象
面试必备 LeetCode 链表算法题汇总,全程干货!
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
PostgreSQLSQL高级技巧透视表
Apachecn translation, proofreading, note sorting activity progress announcement 2022.7
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成