当前位置:网站首页>User password encryption tool
User password encryption tool
2022-08-03 04:40:00 【Dzooooone_】
Encryption
import org.apache.commons.codec.binary.Base64;import javax.crypto.Cipher;import javax.crypto.SecretKey;import javax.crypto.spec.SecretKeySpec;public class CryptoUtil {//Encryption Algorithmprivate static final String DESede_ALGORITHM = "DESede";//With saltprivate static final String KEY = "xxxx";/*** Text encryption** @param plain text to be encrypted* @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;}}/*** Password decryption** @param cryptograph password to be decrypted* @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=="));}}
Encrypt the user password first and then store it in the warehouse
jwt dependencies
io.jsonwebtoken jjwt-impl ${jjwt.version} io.jsonwebtoken jjwt-jackson ${jjwt.version}
边栏推荐
- JS底层手写
- 浏览器监听标签页关闭
- 计组错题集
- UV 裂解的生物素-PEG2-叠氮|CAS:1192802-98-4生物素接头
- 用户密码验证
- t conditional judgment statement and if loop
- 刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
- Test drive: project management module - curd development project
- Live | StarRocks technology insider: low base dictionary global optimization
- Interface test practice | Detailed explanation of the difference between GET / POST requests
猜你喜欢
接口测试实战| GET/POST 请求区别详解
GIS数据漫谈(五)— 地理坐标系统
install ambari
DFS对剪枝的补充
我将GuiLite移植到了STM32F4开发板上
redis键值出现 xacxedx00x05tx00&的解决方法
Shenzhen Offline Registration|StarRocks on AWS: How to conduct rapid and unified analysis of real-time data warehouses
【Harmony OS】【ARK UI】ets使用startAbility或startAbilityForResult方式调起Ability
打破传统电商格局,新型社交电商到底有什么优点?
Windows 安装PostgreSQL
随机推荐
寄存器(内存访问)
浏览器监听标签页关闭
工程水文学试题库
Kotlin-Flow common encapsulation class: the use of StateFlow
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
RequestContextHolder
【开发者必看】【push kit】推送服务服务典型问题合集2
接口测试如何准备测试数据
9.新闻分类:多分类问题
Test drive: project management module - curd development project
Record some bugs encountered - when mapstruct and lombok are used at the same time, the problem of data loss when converting entity classes
Windows 安装PostgreSQL
【uni-APP搭建项目】
接口测试框架实战(三)| JSON 请求与响应断言
Redis缓存雪崩、缓存穿透、缓存击穿
2022 Henan Mengxin League Game (4): Zhengzhou University of Light Industry E - Sleep Well
工程水文学知识点
修饰生物素DIAZO-生物素-PEG3-DBCO|重氮-生物素-三聚乙二醇-二苯基环辛炔
v-on指令:为元素绑定事件