当前位置:网站首页>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));边栏推荐
- Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
- China Indonesia adhesive market trend report, technological innovation and market forecast
- 基于wifi控制的51单片机温度报警器
- Why do you say that the maximum single table of MySQL database is 20million? Based on what?
- Accounting regulations and professional ethics [6]
- The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
- Embedded software architecture design - function call
- NoSQL之readis配置与优化(终章)
- Height residual method
- tp配置多数据库
猜你喜欢

2022PMP考试基本情况详情了解
Application of clock wheel in RPC

对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平

I let the database lock the table! Almost fired!

The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)

Principle and general steps of SQL injection

祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022

Communication mode based on stm32f1 single chip microcomputer

~88 running people practice

How to decrypt worksheet protection password in Excel file
随机推荐
[Acwing] 58周赛 4490. 染色
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
Vscode setting outline shortcut keys to improve efficiency
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
线程池的使用和原理
Maximum subarray and matrix multiplication
2021 Google vulnerability reward program review
APOC custom functions and procedures
ECCV 2022 released: 1629 papers were selected, and the employment rate was less than 20%
GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
[North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
Readis configuration and optimization of NoSQL (final chapter)
Understand ThreadLocal in one picture
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
基于wifi控制的51单片机温度报警器
ECCV 2022放榜了:1629篇论文中选,录用率不到20%
Jump table instance
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
Object. Usage of keys()