当前位置:网站首页>MD5加密的两种方式
MD5加密的两种方式
2022-07-04 15:12:00 【郝少】
目录
一、需求说明
- 在存储密码时,需要进行加密处理。所以为了安全,数据库看到的密码必须是加过密的,这就是后台人员包括工作人员看不到你正真密码,只能改密码的原因;这里简述使用MD5进行加密的两种方法,一种是基于spring-core包的工具进行MD5加密,一个是基于hutool工具类中的封装方法进行加密;
- 在业务逻辑中相同的密码加密之后生成的加密串也是相同的,只需要对比生成后的加密串是否相同,即可判定是否输入了同一个密码。
二、基于spring-core工具加密
这种方式加密方式比较灵活,可以在工具类中多层自定义加密方式;
1、导入依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
2、代码
MD5Util.java
import org.springframework.util.DigestUtils;
//必须得有Spring-core支持
public class MD5Util {
//必须要有Spring-core支持
public static String getMd5Plus(String pwd){
//先进行第一层加密
String md1 = DigestUtils.md5DigestAsHex(pwd.getBytes());
//截取第一层加密后的密文的前6位
String substring6 = md1.substring(0, 6);//前包含后不包含
//再对密文+前6位再加密
String md5plus = DigestUtils.md5DigestAsHex((md1+substring6).getBytes());
return md5plus;
}
}
- 测试
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));
二、基于hutool工具进行加密
1、导入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
2、代码
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));
边栏推荐
- Research Report on market supply and demand and strategy of China's plastics and polymer industry
- Can you really use MySQL explain?
- 世界环境日 | 周大福用心服务推动减碳环保
- Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
- Inside and outside: flow chart drawing elementary: six common mistakes
- Research Report on market supply and demand and strategy of China's well completion equipment industry
- 时序图数据建模与产业链分析
- China Indonesia adhesive market trend report, technological innovation and market forecast
- js中的数组筛选fliter
- Hair and fuzz interceptor Industry Research Report - market status analysis and development prospect forecast
猜你喜欢
电子元器件B2B商城系统开发:赋能企业构建进销存标准化流程实例
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
MFC implementation of ACM basic questions encoded by the number of characters
Detailed process of DC-2 range construction and penetration practice (DC range Series)
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
L1-072 scratch lottery
Vscode setting outline shortcut keys to improve efficiency
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
2022年国内云管平台厂商哪家好?为什么?
容器环境minor gc异常频繁分析
随机推荐
Accounting regulations and professional ethics [9]
C # realizes FFT forward and inverse transformation and frequency domain filtering
Object. Usage of keys()
Oracle监听器Server端与Client端配置实例
Lv166 turned over
c# 实现定义一套中间SQL可以跨库执行的SQL语句
智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
Implement graph data construction task based on check point
2021 Google vulnerability reward program review
Go language loop statement (under Lesson 10)
Array filter fliter in JS
Accounting regulations and professional ethics [11]
Opencv learning -- arithmetic operation of image of basic operation
[Chongqing Guangdong education] National Open University spring 2019 1248 public sector human resource management reference questions
高度剩余法
话里话外:流程图绘制初级:六大常见错误
Anta is actually a technology company? These operations fool netizens
实战:fabric 用户证书吊销操作流程
容器环境minor gc异常频繁分析
Research Report on market supply and demand and strategy of China's plastics and polymer industry