当前位置:网站首页>Two methods of MD5 encryption
Two methods of MD5 encryption
2022-07-04 17:08:00 【Hao Shao】
Catalog
One 、 Requirement specification
Two 、 be based on spring-core Tool encryption
Two 、 be based on hutool Tools to encrypt
One 、 Requirement specification
- When storing passwords , It needs to be encrypted . So for safety , The password seen in the database must be encrypted , This is why the backstage staff, including the staff, can't see your true password , The reason why you can only change your password ; Here is a brief description of the use MD5 There are two ways to encrypt , One is based on spring-core Package tools MD5 encryption , One is based on hutool The encapsulated method in the tool class is encrypted ;
- In the business logic, the encryption string generated after the same password encryption is also the same , Just compare whether the generated encrypted string is the same , You can determine whether the same password has been entered .
Two 、 be based on spring-core Tool encryption
This encryption method is more flexible , You can customize the encryption method at multiple levels in the tool class ;
1、 Import dependence
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>2、 Code
MD5Util.java
import org.springframework.util.DigestUtils;
// Must have Spring-core Support
public class MD5Util {
// There must be Spring-core Support
public static String getMd5Plus(String pwd){
// First, encrypt the first layer
String md1 = DigestUtils.md5DigestAsHex(pwd.getBytes());
// Intercept the first layer of encrypted ciphertext 6 position
String substring6 = md1.substring(0, 6);// Include before not include
// Then the ciphertext + front 6 Bit re encryption
String md5plus = DigestUtils.md5DigestAsHex((md1+substring6).getBytes());
return md5plus;
}
}- test
String pwd="123456";
//033e997f49e0cff004e70b09303f670a
String md5Plus1 = MD5Util.getMd5Plus(pwd);
String login_pwd="123456";
//033e997f49e0cff004e70b09303f670a
String md5Plus2 = MD5Util.getMd5Plus(login_pwd);
//true
System.out.println(md5Plus1.equals(md5Plus2));Two 、 be based on hutool Tools to encrypt
1、 Import dependence
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>2、 Code
String str_pwd="123456";
//e10adc3949ba59abbe56e057f20f883e
String md5Hex1 = DigestUtil.md5Hex(str_pwd);
String str_login_pwd="123456";
//e10adc3949ba59abbe56e057f20f883e
String md5Hex2 = DigestUtil.md5Hex(str_login_pwd);
//true
System.out.println(md5Hex1.equals(md5Hex2));边栏推荐
- APOC自定义函数和过程
- How can programmers improve the speed of code writing?
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- Congratulations to Mr. Zhang Pengfei, chief data scientist of artefact, for winning the campaign Asia tech MVP 2022
- 【云原生】服务网格是什么“格”?
- NoSQL之readis配置与优化(终章)
- Learn more about the basic situation of 2022pmp examination
- 网页游戏引擎
- The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
- Redis 的内存淘汰策略和过期删除策略的区别
猜你喜欢

Go micro tutorial - Chapter 2 go micro V3 using gin and etcd

对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平

昆明三环闭合工程将经过这些地方,有在你家附近的吗?

电子元器件B2B商城系统开发:赋能企业构建进销存标准化流程实例

Start by counting

2022年国内云管平台厂商哪家好?为什么?

一图看懂ThreadLocal

Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry

C# 更加优质的操作MongoDB数据库

7 RSA密码体制
随机推荐
.Net 应用考虑x64生成
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Cypher task design and task locking mechanism of isomorphic and heterogeneous graphs
Learn more about the basic situation of 2022pmp examination
力扣今日题-1200. 最小绝对差
最大子数组与矩阵乘法
安信证券网上开户安全吗 开户收费吗
detectron2安装方法
散列表
MVC模式和三层架构
js中的数组筛选fliter
一图看懂ThreadLocal
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China
Spark 中的 Rebalance 操作以及与Repartition操作的区别
C# 更加优质的操作MongoDB数据库
How to implement a delay queue?
Embedded software architecture design - function call
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
网页游戏引擎