当前位置:网站首页>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));
}
}
边栏推荐
- Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
- MySQL storage data encryption
- 微服务--开篇
- KDD2022 | 什么特征进行交互才是有效的?
- With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
- LOGO特訓營 第一節 鑒別Logo與Logo設計思路
- Representation of confidence interval
- Introduction and application of bigfilter global transaction anti duplication component
- 30余家机构联合发起数字藏品行业倡议,未来会如何前进?
- New intersectionobserver usage notes
猜你喜欢

B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】

机器学习笔记 - 互信息Mutual Information

Bizchart+slider to realize grouping histogram

Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry

玩转gRPC—深入概念与原理

i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED

BigFilter全局交易防重组件的介绍与应用

Huawei Nova 10 series released Huawei application market to build a solid application security firewall

Introduction and application of bigfilter global transaction anti duplication component
随机推荐
WebGIS框架---kalrry
微服务--开篇
TLA+ 入门教程(1):形式化方法简介
迷失在Mysql的锁世界
Apachecn translation, proofreading, note sorting activity progress announcement 2022.7
Why do you have to be familiar with industry and enterprise business when doing Bi development?
Jvm-Sandbox-Repeater的部署
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
The use of complex numbers in number theory and geometry - Cao Zexian
Domestic database chaos
1807. Replace the parentheses in the string
我在linux里面 通过调用odspcmd 查询数据库信息 怎么静默输出 就是只输出值 不要这个
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
sqlserver对数据进行加密、解密
File read write
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
Basic structure of PostgreSQL - table
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
From repvgg to mobileone, including mobileone code