当前位置:网站首页>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));
}
}
边栏推荐
- 国产数据库乱象
- 1807. Replace the parentheses in the string
- Use blocconsumer to build responsive components and monitor status at the same time
- Representation of confidence interval
- 卷积神经网络模型之——LeNet网络结构与代码实现
- Common open source codeless testing tools
- PHP short video source code, thumb animation will float when you like it
- Deployment of JVM sandbox repeater
- 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)
猜你喜欢
力扣98:验证二叉搜索树
Locust性能测试 —— 环境搭建及使用
Why is Dameng data called the "first share" of domestic databases?
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
How to transfer to software testing, one of the high paying jobs in the Internet? (software testing learning roadmap attached)
Concurrent optimization summary
使用 BlocConsumer 同时构建响应式组件和监听状态
卷积神经网络模型之——LeNet网络结构与代码实现
BigFilter全局交易防重组件的介绍与应用
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
随机推荐
湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
The proofreading activity of data science on the command line second edition was restarted
好用app推荐:扫描二维码、扫描条形码并查看历史
Recommendation of mobile app for making barcode
Postgresqlql advanced skills pivot table
删库不必跑路!详解 MySQL 数据恢复
TCP protocol three times handshake process
Practice and principle of PostgreSQL join
PostgreSQL server programming aggregation and grouping
BigFilter全局交易防重组件的介绍与应用
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
Logo special training camp section 1 Identification logo and logo design ideas
服务线上治理
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
How to reset the password of MySQL root account
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
php短视频源码,点赞时会有大拇指动画飘起
不同环境相同配置项的内容如何diff差异?