当前位置:网站首页>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));
}
}
边栏推荐
- WebGIS framework -- kalrry
- La prospérité est épuisée, les choses sont bonnes et mauvaises: Où puis - je aller pour un chef de station personnel?
- i. Mx6ull driver development | 24 - platform based driver model lights LED
- How can the advertising system of large factories be upgraded without the presence of large models
- 30余家机构联合发起数字藏品行业倡议,未来会如何前进?
- Logo special training camp Section V font structure and common design techniques
- 1807. Replace the parentheses in the string
- Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
- Force buckle_ Palindrome number
- Logo special training camp section III initial creative techniques
猜你喜欢
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
Logo special training camp section 1 Identification logo and logo design ideas
【C语言进阶篇】数组&&指针&&数组笔试题
Tiktok actual combat ~ the number of comments is updated synchronously
常用的开源无代码测试工具
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
能源势动:电力行业的碳中和该如何实现?
LOGO special training camp section I identification logo and Logo Design Ideas
Logo Camp d'entraînement section 3 techniques créatives initiales
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
随机推荐
You don't have to run away to delete the library! Detailed MySQL data recovery
Cadre WebGIS - kalrry
Deployment of JVM sandbox repeater
【Acwing】第58场周赛 题解
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
都说软件测试很简单有手就行,但为何仍有这么多劝退的?
The use of complex numbers in number theory and geometry - Cao Zexian
Telephone encryption, middle 4 is replaced by * * * *
面试必备 LeetCode 链表算法题汇总,全程干货!
LOGO特训营 第三节 首字母创意手法
Introduction and application of bigfilter global transaction anti duplication component
Now MySQL cdc2.1 is parsing the datetime class with a value of 0000-00-00 00:00:00
Interview essential leetcode linked list algorithm question summary, whole process dry goods!
With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
玩转gRPC—深入概念与原理
Recommendation of mobile app for making barcode
微服务--开篇
SPSS安装激活教程(包含网盘链接)
Logo special training camp Section V font structure and common design techniques
Tiktok actual combat ~ the number of comments is updated synchronously