当前位置:网站首页>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));边栏推荐
- Median and order statistics
- 高度剩余法
- PingCode 性能测试之负载测试实践
- Understand ThreadLocal in one picture
- MVC模式和三层架构
- Maximum subarray and matrix multiplication
- Solution of commercial supply chain coordination system in the mineral industry: build a digital intelligent supply chain platform to ensure the safe supply of mineral resources
- 跳跃表实例
- [Acwing] 58周赛 4490. 染色
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
猜你喜欢

GO开发:如何利用Go单例模式保障流媒体高并发的安全性?

聊聊异步编程的 7 种实现方式

L1-072 scratch lottery

智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式

Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782

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

世界环境日 | 周大福用心服务推动减碳环保
Redis 的内存淘汰策略和过期删除策略的区别
Why do you say that the maximum single table of MySQL database is 20million? Based on what?

The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
随机推荐
【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
7 RSA密码体制
太方便了,钉钉上就可完成代码发布审批啦!
2022年国内云管平台厂商哪家好?为什么?
How to decrypt worksheet protection password in Excel file
Detailed process of DC-2 range construction and penetration practice (DC range Series)
电子元器件B2B商城系统开发:赋能企业构建进销存标准化流程实例
Start by counting
话里话外:流程图绘制初级:六大常见错误
跳跃表实例
Rebalance operation in spark and its difference from repartition operation
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
Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
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?
Research Report on market supply and demand and strategy of China's well completion equipment industry
线性时间排序
高度剩余法
[acwing] 58 weeks 4490 dyeing
China's plastic processing machinery market trend report, technological innovation and market forecast
[Acwing] 58周赛 4490. 染色