lyhzzz 1 year ago
parent
commit
1579cec998

+ 21 - 8
src/main/java/com/fdkankan/manage_jp/util/EncryptDecrypt.java

@@ -3,6 +3,7 @@ package com.fdkankan.manage_jp.util;
 
 import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
 import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
 import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -74,20 +75,32 @@ public class EncryptDecrypt {
         config.setKeyObtentionIterations("1000");
         config.setPoolSize("1");
         config.setProviderName(null);
-        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
+        config.setSaltGeneratorClassName("org.jasypt.iv.NoIvGenerator");
         config.setStringOutputType("base64");
         return config;
     }
 
     public static void main(String[] args) {
-        // 加密
-        System.out.println("ENC("+encryptPwd("4dage168...", "JK20220120%JIK")+")");
-        // 解密
-//        mysql@1234
-//        System.out.println(decyptPwd("EbfYkitulv73I2p0mXI50JMXoaxZTKJ7", "bgWQ4OfVCUJ1ExsqNhGV+KKBgpx8alv+"));
+        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
+        //配置文件中配置如下的算法
+        standardPBEStringEncryptor.setAlgorithm("PBEWithMD5AndDES");
+        //配置文件中配置的password
+        standardPBEStringEncryptor.setPassword("4dage168...");
+        //要加密的文本
+        String name = standardPBEStringEncryptor.encrypt("root");
+        String password = standardPBEStringEncryptor.encrypt("JK20220120%JIK");
+        String redisPassword = standardPBEStringEncryptor.encrypt("123456");
+        //将加密的文本写到配置文件中
+        System.out.println("name=" + name);
+        System.out.println("password=" + password);
+        System.out.println("redisPassword=" + redisPassword);
+
+        //要解密的文本
+        //String name2 = standardPBEStringEncryptor.decrypt("FarrmxSQX5uwtH/NZRxy+g==");
+        //String password2 = standardPBEStringEncryptor.decrypt("vhiaYB1gl9zPj16yu7uMkA==");
+       // String redisPassword2 = standardPBEStringEncryptor.decrypt("ZII7UphhbVuJ8c3oxPUeyw==");
+        //解密后的文本
 
-//        root@1234
-//        System.out.println(decyptPwd("EbfYkitulv73I2p0mXI50JMXoaxZTKJ7", "tdHzge8YvviOJaiV/+P6uQ9wgB44D1aH"));
     }
 
 }

+ 1 - 0
src/main/resources/bootstrap.yml

@@ -16,4 +16,5 @@ mybatis-plus:
 jasypt:
   encryptor:
     password: 4dage168... #添加的盐
+    algorithm: PBEWithMD5AndDES
     iv-generator-classname: org.jasypt.iv.NoIvGenerator