当前位置:网站首页>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}
边栏推荐
猜你喜欢
随机推荐
v-on指令:为元素绑定事件
传统企业如何转型社交电商,泰山众筹的玩法有哪些?
Bubble sort in c language structure
接口测试框架实战(二)| 接口请求断言
常见荧光染料修饰多种基团及其激发和发射波长数据一览数据
【Harmony OS】【ARK UI】ETS 上下文基本操作
普乐蛙VR台风体验馆厂家VR防震减灾模拟VR沉浸式体验设备
Kotlin-Flow常用封装类:StateFlow的使用
接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
How many moments have you experienced the collapse of electronic engineers?
install ambari
寄存器(内存访问)
[Developers must see] [push kit] Collection of typical problems of push service service 2
"Obs" start pushing flow failure: the Output. The StartStreamFailed call process
Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
Assembly answers
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
工程制图-齿轮
Two ways to simulate multi-user login in Jmeter
Interface test practice | Detailed explanation of the difference between GET / POST requests