当前位置:网站首页>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));
边栏推荐
- Position encoding practice in transformer
- How to implement a delay queue?
- Jump table instance
- How to "use" Perl modules in directories that are not in @inc- How do I 'use' a Perl module in a directory not in @INC?
- Redis 的内存淘汰策略和过期删除策略的区别
- Object.keys()的用法
- Array filter fliter in JS
- C# 服务器日志模块
- How to decrypt worksheet protection password in Excel file
- Understand ThreadLocal in one picture
猜你喜欢
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
Object.keys()的用法
Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782
Readis configuration and optimization of NoSQL (final chapter)
Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
Why do you say that the maximum single table of MySQL database is 20million? Based on what?
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
S2b2b solution for lighting industry: efficiently enable the industrial supply chain and improve the economic benefits of enterprises
随机推荐
时序图数据建模与产业链分析
C # realizes FFT forward and inverse transformation and frequency domain filtering
Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry
7 RSA密码体制
力扣今日题-1200. 最小绝对差
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
ECCV 2022 released: 1629 papers were selected, and the employment rate was less than 20%
安信证券排名 网上开户安全吗
tp配置多数据库
Market trend report, technical innovation and market forecast of taillight components in China
[Acwing] 58周赛 4490. 染色
Readis configuration and optimization of NoSQL (final chapter)
PingCode 性能测试之负载测试实践
Overflow: the combination of auto and Felx
c# 实现定义一套中间SQL可以跨库执行的SQL语句
2022PMP考试基本情况详情了解
Which domestic cloud management platform manufacturer is good in 2022? Why?
Array filter fliter in JS
如何为ONgDB核心项目源码做贡献