当前位置:网站首页>用户密码加密工具
用户密码加密工具
2022-08-03 04:35:00 【Dzooooone_】
加密类
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class CryptoUtil {
//加密算法
private static final String DESede_ALGORITHM = "DESede";
//加盐
private static final String KEY = "xxxx";
/**
* 文本加密
*
* @param plain 待加密文本
* @return
* @throws Exception
*/
public static final String encrypt(String plain) {
byte[] newKeys = getKeys(KEY);
try {
SecretKey secureKey = new SecretKeySpec(newKeys, DESede_ALGORITHM);
Cipher cipher = Cipher.getInstance(DESede_ALGORITHM);
cipher.init(1, secureKey);
byte[] encrypted = cipher.doFinal(plain.getBytes());
return new String(Base64.encodeBase64(encrypted));
} catch (Exception e) {
return null;
}
}
/**
* 密码解密
*
* @param cryptograph 待解密密码
* @return
* @throws Exception
*/
public static final String decrypt(String cryptograph) {
byte[] newKeys = getKeys(KEY);
byte[] encrypted = Base64.decodeBase64(cryptograph.getBytes());
try {
SecretKey secureKey = new SecretKeySpec(newKeys, DESede_ALGORITHM);
Cipher cipher = Cipher.getInstance(DESede_ALGORITHM);
cipher.init(2, secureKey);
byte[] cryptoGraphs = cipher.doFinal(encrypted);
return new String(cryptoGraphs);
} catch (Exception e) {
return null;
}
}
private static byte[] getKeys(String key) {
byte[] oldKeys = KEY.getBytes();
byte[] newKeys = new byte[24];
for (int i = 0; i < oldKeys.length && i != 24; i++)
newKeys[i] = oldKeys[i];
return newKeys;
}
public static void main(String[] args) throws Exception {
System.out.println(CryptoUtil.encrypt("xxxxxx"));
System.out.println(CryptoUtil.decrypt("gySSNZWJIyQ="));
System.out.println(CryptoUtil.decrypt("/4lOgQ80Y9LVB69nhkR1tA=="));
}
}对用户密码先进行加密后再入库
jwt依赖
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
</dependency>边栏推荐
猜你喜欢

Bubble sort in c language structure

多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG

在竞争白热化的电商行业,链动2+1为什么还有企业在用

接口管理工具YApi怎么用?颜值高、易管理、超好用

RequestContextHolder

4.深度学习的几何解释与梯度的优化

Online password generator tool recommendation

【Harmony OS】【ARK UI】Date 基本操作

CobalStrike(CS)基础超级详细版

【Harmony OS】【FAQ】Hongmeng Questions Collection 1
随机推荐
测开:项目管理模块-项目curd开发
2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
数据库基本概述与SQL概述
工程制图点的投影练习
那些让电子工程师崩溃瞬间,你经历了几个呢?
「短视频+社交电商」营销模式爆发式发展,带来的好处有什么?
Redis缓存雪崩、缓存穿透、缓存击穿
MySQL 删除表数据,重置自增 id 为 0 的两个方式
Two ways to simulate multi-user login in Jmeter
Bubble sort in c language structure
11.机器学习基础:机器学习的四个分支
Shell编程的条件语句
超好用的画图工具推荐
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
4.深度学习的几何解释与梯度的优化
接口测试如何准备测试数据
2022/08/02 学习笔记 (day22) 多线程
数字化时代,企业如何建立自身的云平台与商业模式的选择?
How many moments have you experienced the collapse of electronic engineers?
Jmeter 模拟多用户登录的两种方法