当前位置:网站首页>用户密码加密工具
用户密码加密工具
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>
边栏推荐
- 软件开发的最大的区别是什么?
- How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use
- CobalStrike(CS)基础超级详细版
- 移动流量的爆发式增长,社交电商如何选择商业模式
- 【Harmony OS】【FAQ】鸿蒙问题合集1
- 数值类型转换02
- Technology Sharing | How to do assertion verification for xml format in interface automation testing?
- 【翻译】开发与生产中的Kubernetes修复成本对比
- 接口管理工具YApi怎么用?颜值高、易管理、超好用
- JS bottom handwriting
猜你喜欢
随机推荐
IO进程线程->线程->day5
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
Live | StarRocks technology insider: low base dictionary global optimization
easyswoole的mysqli 事务怎么写
软件开发的最大的区别是什么?
MySQL 删除表数据,重置自增 id 为 0 的两个方式
如何利用 Flutter 实现炫酷的 3D 卡片和帅气的 360° 展示效果
Kotlin-Flow常用封装类:StateFlow的使用
移动流量的爆发式增长,社交电商如何选择商业模式
自考六级雅思托福备战之路
BIOTIN ALKYNE CAS:773888-45-2价格,供应商
数字化时代,企业如何建立自身的云平台与商业模式的选择?
Interface testing framework combat (3) | JSON request and response assertion
JS底层手写
Windows 安装PostgreSQL
I ported GuiLite to STM32F4 board
IDEC和泉触摸屏维修HG2F-SS22V HG4F软件通信分析
redis键值出现 xacxedx00x05tx00&的解决方法
测开:项目管理模块-项目curd开发
LeetCode算法日记:面试题 03.04. 化栈为队