当前位置:网站首页>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 ");
}
}
}
边栏推荐
- SAP UI5 应用开发教程之一百零二 - SAP UI5 应用的打印(Print)功能实现详解
- 美团基于 Flink 的实时数仓平台建设新进展
- Thead Safety心得体会
- Is Ruida futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
- IPV4的未来替代品!一文读懂IPV6的优势特点和地址类型
- Brief introduction: how much do you know about fishing attacks
- [arm] it is reported that horizontal display is set for LVDS screen of rk3568 development board
- Ecmascript6 new features
- Several abnormal scenarios of things system
- Customize multi-level list styles in word
猜你喜欢

Isolation level of transaction system

SAP MM 事务代码VL04为STO创建外向交货单

KunlunDB备份和恢复

Synchronization circuit and cross clock domain circuit design 2 -- cross clock domain transmission (FIFO) of multi bit signals

SAP UI5 应用开发教程之一百零二 - SAP UI5 应用的打印(Print)功能实现详解试读版

Flutter outsourcing, undertaking flutter project

OJ daily practice - filter extra spaces

Introduction to the unique variable reading and writing function of Kunlun distributed database

Leakcanary source code (2)

07 项目成本管理
随机推荐
【首发】Redis系列2:数据持久化提高可用性
【ARM】讯为rk3568开发板lvds屏设置横屏显示
Synchronization circuit and cross clock domain circuit design 2 -- cross clock domain transmission (FIFO) of multi bit signals
KunlunDB查询优化(二)Project和Filter下推
TIDB监控升级解决panic的漫漫探索之路
How to use enum data types
Notes on zhouguohua's reading
Php7.3 error undefined function simplexml_ load_ string()
在Word中自定义多级列表样式
ROS2暑期学校 ROS2 Summer School 2022-转-
在一条DML语句中插入/更新/删除/获取几百万行数据,你会特别注意什么?
flowable 全局监听 监听流程的启动和流程的结束
SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库
[go] go modules GETTING STARTED
Redistemplate encountered problems with \x00
【UVM】别再说你的 VIP 用不了 RAL Model
DCC888 :SSA (static single assignment form)
因为我说:volatile 是轻量级的 synchronized,面试官让我回去等通知!
昆仑分布式数据库技术优势
【GO】go语言interface