当前位置:网站首页>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));
}
}
边栏推荐
- 力扣3_383. 赎金信
- idea中pom.xml依赖无法导入
- Logo special training camp section 1 Identification logo and logo design ideas
- What is the stock account opening process? Is it safe to use flush mobile stock trading software?
- 现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
- Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
- 【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
- UML图记忆技巧
- md5工具类
- 虚拟人产业面临的挑战
猜你喜欢
LOGO特训营 第一节 鉴别Logo与Logo设计思路
LOGO特训营 第三节 首字母创意手法
Concurrent optimization summary
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
并发优化总结
Convolutional neural network model -- lenet network structure and code implementation
UML diagram memory skills
Machine learning notes mutual information
LOGO special training camp section I identification logo and Logo Design Ideas
随机推荐
Jvm-Sandbox-Repeater的部署
LOGO特训营 第四节 字体设计的重要性
How to manage 15million employees easily?
Convolutional neural network model -- lenet network structure and code implementation
Tiktok actual combat ~ the number of comments is updated synchronously
面试必备 LeetCode 链表算法题汇总,全程干货!
Concurrent network modular reading notes transfer
力扣98:验证二叉搜索树
Play with grpc - go deep into concepts and principles
i. Mx6ull driver development | 24 - platform based driver model lights LED
Kdd2022 | what features are effective for interaction?
Locust性能测试 —— 环境搭建及使用
国产数据库乱象
Introduction and application of bigfilter global transaction anti duplication component
WebGIS framework -- kalrry
php短视频源码,点赞时会有大拇指动画飘起
UML图记忆技巧
好用app推荐:扫描二维码、扫描条形码并查看历史
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
What is the stock account opening process? Is it safe to use flush mobile stock trading software?