当前位置:网站首页>MD5 encryption + salt value tool class
MD5 encryption + salt value tool class
2022-06-22 23:58:00 【gblfy】
package com.gblfy.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import java.util.UUID;
/**
* MD5 encryption + Salt value tools
*
* @author gblfy
* @Date 2022-06-22
**/
@Slf4j
@Component
public class MD5Utils {
/**
* Perform password encryption
*
* @param password The original password
* @param salt Salt value
* @return Encrypted ciphertext
*/
public static String getMd5Password(String password, String salt) {
/*
* Encryption rules :
* 1、 Ignore the strength of the original password
* 2、 Use UUID As the salt value , Splice the left and right sides of the original password
* 3、 Cyclic encryption 3 Time
*/
for (int i = 0; i < 3; i++) {
password = DigestUtils.md5DigestAsHex((salt + password + salt).getBytes()).toUpperCase();
}
return password;
}
/**
* Password check
*
* @param dbSalt Database salt value
* @param password Front end parameter transmission password
* @param dbMd5Password Password after database encryption
* @return true- Passwords are equal false- The passwords are not equal
*/
public static Boolean comparePasswordsForEquality(String dbSalt, String dbMd5Password, String password) {
String md5Password = MD5Utils.getMd5Password(password, dbSalt);
log.info(" Front page parameter password -md5 encryption + Password after salt value ->{}", md5Password);
if (dbMd5Password.equals(md5Password)) {
return true;
}
return false;
}
public static void main(String[] args) {
//-------------------------------------------md5+ Salt value generates password -------------------------------------------
//1. Generate md5+ Salt value password
String salt = UUID.randomUUID().toString().toUpperCase();
// The original password
String password = "123456";
// Password after database encryption
String dbMd5Password = MD5Utils.getMd5Password(password, salt);
log.info("md5 encryption + Password after salt value ->{}", dbMd5Password);
//------------------------------------------- become md5+ Salt value password comparison -------------------------------------------
// Front end parameter transmission password
String frontPagePasswordParam = "123456";
// Database salt value
String dbSalt = salt;
if (MD5Utils.comparePasswordsForEquality(dbSalt, dbMd5Password, frontPagePasswordParam)) {
System.out.println(" The password is the same ");
} else {
System.out.println(" The passwords are different ");
}
}
}
边栏推荐
- MD5加密+盐值工具类
- SAP UI5 应用开发教程之一百零二 - SAP UI5 应用的打印(Print)功能实现详解试读版
- 语义分割新范式!StructToken:对per-pixel 分类范式的重新思考
- SAP MM 事务代码VL04为STO创建外向交货单
- XML escape character cross reference table
- 昆仑分布式数据库Sequence功能及其实现机制
- KunlunDB查询优化(二)Project和Filter下推
- [go] go array and slice (dynamic array)
- Express、路由(Route)、Request对象、Response对象、中间件、EJS模板
- Php7.3 error undefined function simplexml_ load_ string()
猜你喜欢

MySQL-Seconds_behind_master 的精度误差

EasyCVR使用RTMP推流时不显示界面如何解决?
![How Huawei cloud implements a global low delay network architecture for real-time audio and video [Part 1]](/img/70/dcb558cf265da9e396637c5b90cd1b.png)
How Huawei cloud implements a global low delay network architecture for real-time audio and video [Part 1]

SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库

考过HCIP依然转行失败,职业网工最看重的到底是什么
![[go] go modules GETTING STARTED](/img/0a/58c50bb624c91b88a88aea280aa650.jpg)
[go] go modules GETTING STARTED

Several abnormal scenarios of things system

Kunlundb query optimization (III) sort push down

ROS1Noetic在Win11中安装记录

After passing the hcip exam, I still failed to change my career. What do professional network workers value most
随机推荐
MySQL8.0轻松完成GTID主从复制
os. When the command line parameter in args[1:] is empty, the internal statement will not be executed
EasyCVR硬件盒子如何设置断电自启动
SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库试读版
Kunlundb query optimization (II) project and filter push down
【UVM】别再说你的 VIP 用不了 RAL Model
关于测试/开发程序员技术的一些思考,水平很高超的,混不下去了......
DCC888 :SSA (static single assignment form)
DCC888 :SSA (static single assignment form)
Future alternatives to IPv4! Read the advantages, features and address types of IPv6
07 项目成本管理
如何使用enum数据类型
因为我说:volatile 是轻量级的 synchronized,面试官让我回去等通知!
权限想要细化到按钮,怎么做?
To establish a cloud computing "Kunlun", why should Lenovo hybrid cloud Lenovo xcloud?
Ansible 学习总结(7)—— Ansible 状态管理相关知识总结
RedisTemplate使用遇到\x00的问题
周国华 读书随记
Why do we not use foreign keys now (2)?
一文简述:钓鱼攻击知多少