当前位置:网站首页>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));
边栏推荐
- 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
- 多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
- ~89 deformation translation
- Detailed process of DC-2 range construction and penetration practice (DC range Series)
- 安信证券排名 网上开户安全吗
- 程序员怎么才能提高代码编写速度?
- Implement graph data construction task based on check point
- detectron2安装方法
- DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
- 祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
猜你喜欢
PingCode 性能测试之负载测试实践
How to decrypt worksheet protection password in Excel file
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
2022PMP考试基本情况详情了解
Learn more about the basic situation of 2022pmp examination
C# 服务器日志模块
矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应
随机推荐
51 single chip microcomputer temperature alarm based on WiFi control
【云原生】服务网格是什么“格”?
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
S2b2b solution for lighting industry: efficiently enable the industrial supply chain and improve the economic benefits of enterprises
安信证券网上开户安全吗 开户收费吗
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应
Is it safe to open an account online
SQL implements split
go-micro教程 — 第二章 go-micro v3 使用Gin、Etcd
Is it safe for Anxin securities to open an account online? Is the account opening fee charged
C# 更加优质的操作MongoDB数据库
Hash table
Implement graph data construction task based on check point
安信证券属于什么档次 开户安全吗
[acwing] 58 weeks 4489 Longest subsequence
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
How can programmers improve the speed of code writing?
Research Report on market supply and demand and strategy of China's well completion equipment industry
Start by counting