当前位置:网站首页>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));
}
}
边栏推荐
- VIM from dislike to dependence (23) -- the last gossip
- La prospérité est épuisée, les choses sont bonnes et mauvaises: Où puis - je aller pour un chef de station personnel?
- 并发优化总结
- 湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
- Telephone encryption, middle 4 is replaced by * * * *
- Tiktok actual combat ~ the number of comments is updated synchronously
- LOGO特训营 第五节 字体结构与设计常用技法
- Deployment of JVM sandbox repeater
- 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
- Implementation rules for archiving assessment materials of robot related courses 2022 version
猜你喜欢
i. Mx6ull driver development | 24 - platform based driver model lights LED
常用的开源无代码测试工具
玩转gRPC—深入概念与原理
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
将QA引入软件开发生命周期是工程师要遵循的最佳实践
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
Concurrent network modular reading notes transfer
Logo Camp d'entraînement section 3 techniques créatives initiales
LOGO特训营 第五节 字体结构与设计常用技法
随机推荐
LOGO特训营 第一节 鉴别Logo与Logo设计思路
É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)
Jvm-Sandbox-Repeater的部署
机器人相关课程考核材料归档实施细则2022版本
Cadre WebGIS - kalrry
傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
UML diagram memory skills
《命令行上的数据科学第二版》校对活动重新启动
UML图记忆技巧
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
并发网络模块化 读书笔记转
Practice and principle of PostgreSQL join
Why should garment enterprises talk about informatization?
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
Use blocconsumer to build responsive components and monitor status at the same time
LOGO特训营 第三节 首字母创意手法
服务线上治理
Force buckle 2_ 1480. Dynamic sum of one-dimensional array