当前位置:网站首页>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));
}
}
边栏推荐
- close系统调用分析-性能优化
- 嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
- 传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
- É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)
- Why should garment enterprises talk about informatization?
- The drawing method of side-by-side diagram, multi row and multi column
- 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
- Locust性能测试 —— 环境搭建及使用
- UML图记忆技巧
- Service online governance
猜你喜欢

Introducing QA into the software development lifecycle is the best practice that engineers should follow

Machine learning notes mutual information
![[Yugong series] go teaching course 003-ide installation and basic use in July 2022](/img/65/b36ca239e06a67c01d1eb0b4648f71.png)
[Yugong series] go teaching course 003-ide installation and basic use in July 2022

Scala下载和配置

抖音实战~评论数量同步更新

TCP protocol three times handshake process

The use of complex numbers in number theory and geometry - Cao Zexian

Challenges faced by virtual human industry

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

卷积神经网络模型之——LeNet网络结构与代码实现
随机推荐
机器人相关课程考核材料归档实施细则2022版本
PostgreSQL server programming aggregation and grouping
服务线上治理
傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Logo special training camp section III initial creative techniques
PHP short video source code, thumb animation will float when you like it
SPSS安装激活教程(包含网盘链接)
# 2156. Find the substring of the given hash value - post order traversal
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
Use blocconsumer to build responsive components and monitor status at the same time
常用的开源无代码测试工具
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
Shell 脚本实现应用服务日志入库 Mysql
VIM from dislike to dependence (23) -- the last gossip
ACM Multimedia 2022 | 视觉语言预训练模型中社会偏见的反事实衡量和消除
Huawei Nova 10 series released Huawei application market to build a solid application security firewall
Easy to use app recommendation: scan QR code, scan barcode and view history
BigFilter全局交易防重组件的介绍与应用
嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧