当前位置:网站首页>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}
边栏推荐
- Interface test framework combat (1) | Requests and interface request construction
- Interface testing framework combat (3) | JSON request and response assertion
- 【Harmony OS】【ARK UI】Date 基本操作
- I ported GuiLite to STM32F4 board
- RequestContextHolder
- 在竞争白热化的电商行业,链动2+1为什么还有企业在用
- 社交电商:流量红利已尽,裂变营销是最低成本的获客之道
- 接口测试框架实战(一) | Requests 与接口请求构造
- v-text指令:设置标签内容
- 【Harmony OS】【FAQ】Hongmeng Questions Collection 1
猜你喜欢
v-text指令:设置标签内容
9.新闻分类:多分类问题
redis键值出现 xacxedx00x05tx00&的解决方法
IO进程线程->线程->day5
Record some bugs encountered - when mapstruct and lombok are used at the same time, the problem of data loss when converting entity classes
DFS对剪枝的补充
数字化时代,企业如何建立自身的云平台与商业模式的选择?
Interface Test Framework Practice (4) | Get Schema Assertion
DDL操作数据库、表、列
t conditional judgment statement and if loop
随机推荐
汇编题答案
常见亲脂性细胞膜染料DiO, Dil, DiR, Did光谱图和实验操作流程
C#异步和多线程
接口和协议
中断系统需要解决的问题
寄存器(内存访问)
超好用的画图工具推荐
Unity2D horizontal board game tutorial 6 - enemy AI and attack animation
2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
常见荧光染料修饰多种基团及其激发和发射波长数据一览数据
Interface test Mock combat (2) | Combined with jq to complete batch manual Mock
2.何为张量
【Harmony OS】【ARK UI】Date 基本操作
【Harmony OS】【ArkUI】ets开发 基础页面布局与数据连接
Test drive: project management module - curd development project
传统企业如何转型社交电商,泰山众筹的玩法有哪些?
接口测试框架实战 | 流程封装与基于加密接口的测试用例设计
I ported GuiLite to STM32F4 board
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
Online password generator tool recommendation