当前位置:网站首页>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));
边栏推荐
- 周大福践行「百周年承诺」,真诚服务推动绿色环保
- System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
- Sequence diagram data modeling and industrial chain analysis
- APOC自定义函数和过程
- Learn more about the basic situation of 2022pmp examination
- 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
- Readis configuration and optimization of NoSQL (final chapter)
- 世界环境日 | 周大福用心服务推动减碳环保
- 2022PMP考试基本情况详情了解
- 建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
猜你喜欢
go-micro教程 — 第二章 go-micro v3 使用Gin、Etcd
leetcode:421. 数组中两个数的最大异或值
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
C# 服务器日志模块
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
Redis 的内存淘汰策略和过期删除策略的区别
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
照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益
Embedded software architecture design - function call
太方便了,钉钉上就可完成代码发布审批啦!
随机推荐
js中的数组筛选fliter
2022PMP考试基本情况详情了解
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
7 RSA密码体制
多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
NoSQL之readis配置与优化(终章)
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
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?
Oracle监听器Server端与Client端配置实例
Understand asp Net core - Authentication Based on jwtbearer
中银证券网上开户安全吗?
[glide] cache implementation - memory and disk cache
电子元器件B2B商城系统开发:赋能企业构建进销存标准化流程实例
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
Lv166 turned over
【云原生】服务网格是什么“格”?
tp配置多数据库
Research Report on market supply and demand and strategy of China's Sodium Tetraphenylborate (cas+143-66-8) industry
Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
Height residual method