当前位置:网站首页>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));
边栏推荐
- Lv166 turned over
- Oracle监听器Server端与Client端配置实例
- Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
- 51 single chip microcomputer temperature alarm based on WiFi control
- Jump table instance
- Learn more about the basic situation of 2022pmp examination
- Research Report on market supply and demand and strategy of surgical stapler industry in China
- GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
- Object.keys()的用法
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
猜你喜欢
overflow:auto与felx结合的用法
Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
Learn more about the basic situation of 2022pmp examination
Embedded software architecture design - function call
Yanwen logistics plans to be listed on Shenzhen Stock Exchange: it is mainly engaged in international express business, and its gross profit margin is far lower than the industry level
容器环境minor gc异常频繁分析
Understand asp Net core - Authentication Based on jwtbearer
Analysis of abnormal frequency of minor GC in container environment
The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
聊聊异步编程的 7 种实现方式
随机推荐
The test experience "tortured" by the PMP test is worth your review
【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
Research Report on market supply and demand and strategy of China's Sodium Tetraphenylborate (cas+143-66-8) industry
Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
线性时间排序
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
Oracle监听器Server端与Client端配置实例
程序员怎么才能提高代码编写速度?
如何实现一个延时队列 ?
Which domestic cloud management platform manufacturer is good in 2022? Why?
Analysis of abnormal frequency of minor GC in container environment
ONgDB图数据库与Spark的集成
China's plastic processing machinery market trend report, technological innovation and market forecast
最大子数组与矩阵乘法
Array filter fliter in JS
散列表
Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
聊聊异步编程的 7 种实现方式
Understand asp Net core - Authentication Based on jwtbearer