当前位置:网站首页>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} 边栏推荐
- unity2D横板游戏教程6-敌人AI以及受击动画
- 【Harmony OS】【ARK UI】ets使用startAbility或startAbilityForResult方式调起Ability
- "Obs" start pushing flow failure: the Output. The StartStreamFailed call process
- t conditional judgment statement and if loop
- GIS数据漫谈(五)— 地理坐标系统
- Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?
- 计网试卷概念
- v-text指令:设置标签内容
- OSI的分层特点、传输过程与三次握手、四次挥手、tcp与udp包头的描述
- Problems that need to be solved for interrupting the system
猜你喜欢
随机推荐
荧光标记多肽FITC/AMC/FAM/Rhodamine/TAMRA/Cy3/Cy5/Cy7-Peptide
install ambari
中断系统需要解决的问题
【Harmony OS】【ArkUI】ets开发 基础页面布局与数据连接
JS底层手写
【Harmony OS】【ARK UI】轻量级数据存储
CobalStrike(CS)基础超级详细版
接口测试框架实战(二)| 接口请求断言
MySQL 入门:Case 语句很好用
js的垃圾回收机制
Dialog manager in the fourth chapter: the dialog message loop
5.回顾简单的神经网络
【Harmony OS】【FAQ】鸿蒙问题合集1
GIS数据漫谈(五)— 地理坐标系统
Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
How to prepare for the test interface test data
t条件判断语句与if循环
EssilorLuxottica借助Boomi的智能集成平台实现订单处理的现代化
计网试卷概念
我将GuiLite移植到了STM32F4开发板上








