当前位置:网站首页>md5工具类
md5工具类
2022-07-04 22:00:00 【wgq18586361686】
package com.example.springboottemplate.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* MD5加密工具类
*/
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加密 (大写)
*
* @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加密(小写)
*
* @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));
}
}
边栏推荐
- Flask 上下文详解
- Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
- Relational database
- How can the advertising system of large factories be upgraded without the presence of large models
- 机器学习笔记 - 互信息Mutual Information
- LOGO special training camp section I identification logo and Logo Design Ideas
- Force buckle 3_ 383. Ransom letter
- Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
- Why should garment enterprises talk about informatization?
- PMO:比较25种分子优化方法的样本效率
猜你喜欢

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

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

Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry

Challenges faced by virtual human industry

【C语言进阶篇】数组&&指针&&数组笔试题

Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game

Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel

将QA引入软件开发生命周期是工程师要遵循的最佳实践

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

Common open source codeless testing tools
随机推荐
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
阿里推出新品牌“瓴羊”,致力成为“数字化领头羊”
嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
Easy to use app recommendation: scan QR code, scan barcode and view history
Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
Why should garment enterprises talk about informatization?
i. Mx6ull driver development | 24 - platform based driver model lights LED
TCP protocol three times handshake process
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
MySQL storage data encryption
TLA+ 入门教程(1):形式化方法简介
Challenges faced by virtual human industry
使用 BlocConsumer 同时构建响应式组件和监听状态
What is business intelligence (BI), just look at this article is enough
不同环境相同配置项的内容如何diff差异?
idea中pom.xml依赖无法导入
并发网络模块化 读书笔记转
El tree combined with El table, tree adding and modifying operations
É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)
Spatiotemporal prediction 3-graph transformer