当前位置:网站首页>安全的Md5加密:两次加密(加盐)
安全的Md5加密:两次加密(加盐)
2022-08-09 07:53:00 【CS打赢你】
导包:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
加密类:
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
/**
*
* @author yhq
* @date 2018/8/21 1:09
*
* 两次加密
* 1,在前端:明文密码+固定盐在装成md5
* 2,服务端:获取到传输过来的MD5,在加随机生成的盐,salt,再转成md5,存入数据库(数据库有password和salt字段),存密码的两次MD5生成的值和随机盐
*
*
*/
public class MD5Utils {
private static final String salt = "1a2b3c4d"; //这个自定义
public static String md5(String sac){
//commons-lang3 version:3.6
String md5 = DigestUtils.md5Hex(sac);
System.out.println(md5);
return md5;
}
/**
* 第一次明文加固定salt加密
* @param inputPass
* @return
*/
public static String inputPassToFormPass(String inputPass){
String str = ""+salt.charAt(0)+salt.charAt(2) + inputPass +salt.charAt(5) + salt.charAt(4);
System.out.println(str);
return md5(str);
}
/**
* 第二次加密md5的值+随机盐再进行md5加密
* @param formPass
* @param salt
* @return
*/
public static String formPassToDBPass(String formPass, String salt){
String str = ""+salt.charAt(0)+salt.charAt(2) + formPass +salt.charAt(5) + salt.charAt(4);
System.out.println(str);
return md5(str);
}
/**
* 整体加密
*
*/
public static String inputPassToDbPass(String pass ,String salt){
//第一次加密
String onePass = inputPassToFormPass(pass);
//第二次加密
return formPassToDBPass(onePass,salt);
}
边栏推荐
- PyTorch中 torch.nn与torch.nn.functional的区别
- nvm安装以及管理多版本node教程
- 链表专项练习(四)
- DIMP:Learning Discriminative Model Prediction for Tracking 学习判别模型预测的跟踪
- pc端ncnn搭建与测试
- ncnn 推理猫狗识别
- 74HC595 chip pin description
- tianqf's problem-solving ideas
- 74HC595芯片引脚说明
- The String class objects created by the JVM memory allocation and the difference between equals and = =
猜你喜欢
LeetCode·每日一题·761.特殊的二进制序列·分治
SDRAM的数据存储实现并对其数据进行读写操作
Change Jupyter Notebook default open directory
信息反馈平台的设计与实现(一、项目设计)
Win10桌面图标排列混乱
【机器学习】降维代码练习
Four departments including the Ministry of Industry and Information Technology promote green smart home products to the countryside
74HC595芯片引脚说明
数据库索引原理
3安装及管理程序
随机推荐
权限(下)
Important news丨.NET Core 3.1 will end support on December 13 this year
.net(三) 项目结构
EXCEL uses function joint debugging (find, mid, vlookup, xlookup)
毕业我选择了保家卫国,退伍我选择了华为外包
2019南昌网络赛 C题,Hello 2019
View log common commands
Apache POI
【机器学习】降维代码练习
A brief introduction to microservice architecture
975. 奇偶跳 有序集合
2019 Nanchang Internet Competition Question C, Hello 2019
练习电影卡片、过渡、动画、变形、旋转,练习时钟、立方体、缩放
74HC595 chip pin description
LVM与磁盘配额
LeetCode·每日一题·761.特殊的二进制序列·分治
定时任务组件Quartz
SDRAM的数据存储实现并对其数据进行读写操作
Lottie系列四:使用建议
Neural Network Optimizer