当前位置:网站首页>安全的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);
}
边栏推荐
猜你喜欢
Four departments including the Ministry of Industry and Information Technology promote green smart home products to the countryside
重要消息丨.NET Core 3.1 将于今年12月13日结束支持
C语言:调整奇数偶数顺序
Use tensorflow.keras to build a neural network model modularly
ImportError: cannot import name ‘imresize‘
[STL]string
(三)、时间序列预测
C#基础学习
.net(五) 业务层实现
(error) NOAUTH Authentication required.
随机推荐
yolov5 detects the number of labels in the dataset
Exclude null values when Oracle limits
nvm安装以及管理多版本node教程
3安装及管理程序
libtorch示例
C language: reverse character order
LVM与磁盘配额
tianqf's problem-solving ideas
View log common commands
HDU - 3183 A Magic Lamp 线段树
db2数据库备份恢复问题
RAID配置实战
C language: adjust the order of odd and even numbers
The maximum validity period of an SSL certificate is 13 months. Is it necessary to apply for multiple years at a time?
数据库索引原理
975. 奇偶跳 有序集合
74HC595 chip pin description
web自动化测试有哪些工具和框架?
Pytorch 训练技巧
软件测试的岗位会越来越少吗?