当前位置:网站首页>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} 边栏推荐
猜你喜欢

社交电商如何做粉丝运营?云平台怎么选择商业模式?

I ported GuiLite to STM32F4 board

【Harmony OS】【ArkUI】ets开发 基础页面布局与数据连接

深圳线下报名|StarRocks on AWS:如何对实时数仓进行极速统一分析

接口测试框架实战 | 流程封装与基于加密接口的测试用例设计

工程制图第九章作业

Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?

MySQL 入门:Case 语句很好用

Jmeter 模拟多用户登录的两种方法

Kotlin-Flow common encapsulation class: the use of StateFlow
随机推荐
计组错题集
Test drive: project management module - curd development project
软件开发的最大的区别是什么?
「短视频+社交电商」营销模式爆发式发展,带来的好处有什么?
MySql 创建索引
2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
OSI的分层特点、传输过程与三次握手、四次挥手、tcp与udp包头的描述
Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?
7.Keras开发简介
接口测试实战| GET/POST 请求区别详解
【精讲】利用原生js实现todolist
打破传统电商格局,新型社交电商到底有什么优点?
8.电影评论分类:二分类问题
接口管理工具YApi怎么用?颜值高、易管理、超好用
Interface test Mock combat (2) | Combined with jq to complete batch manual Mock
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
汇编书摘抄
6.神经网络剖析
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
测试人员的价值体现在哪里