当前位置:网站首页>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} 边栏推荐
猜你喜欢
随机推荐
浏览器监听标签页关闭
Shell之条件语句
富瑞宣布战略交易,以简化运营,持续专注于打造领先的独立全服务型全球投行公司
常见亲脂性细胞膜染料DiO, Dil, DiR, Did光谱图和实验操作流程
Interface test Mock combat (2) | Combined with jq to complete batch manual Mock
Shell编程的条件语句
Interface testing framework combat (3) | JSON request and response assertion
Redis缓存雪崩、缓存穿透、缓存击穿
install ambari
Live | StarRocks technology insider: low base dictionary global optimization
Problems that need to be solved for interrupting the system
接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
在线密码生成工具推荐
「短视频+社交电商」营销模式爆发式发展,带来的好处有什么?
测试人员的价值体现在哪里
私域流量时代来临,电商企业如何布局?
荧光标记多肽FITC/AMC/FAM/Rhodamine/TAMRA/Cy3/Cy5/Cy7-Peptide
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
数值类型转换02
13.机器学习基础:数据预处理与特征工程









