|
|
@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
|
|
|
|
import org.jasypt.encryption.StringEncryptor;
|
|
|
|
import org.jasypt.encryption.StringEncryptor;
|
|
|
|
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
|
|
|
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
|
|
|
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
|
|
|
|
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
|
|
|
|
|
|
|
|
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
|
|
|
|
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
|
|
|
|
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
@ -23,50 +24,27 @@ public class jasyptEncryptUtils {
|
|
|
|
final static String PREFIX = "PINN@[";
|
|
|
|
final static String PREFIX = "PINN@[";
|
|
|
|
final static String SUFFIX = "]";
|
|
|
|
final static String SUFFIX = "]";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
public static void main(String[] args) {
|
|
|
|
* Jasypt生成加密结果
|
|
|
|
HashMap<String, String> dataSource = MapUtil.newHashMap();
|
|
|
|
*
|
|
|
|
dataSource.put("url","jdbc:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
|
|
|
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
|
|
|
|
dataSource.put("username","nacos");
|
|
|
|
* @param value 待加密值
|
|
|
|
dataSource.put("password","nacos2233");
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String encryptPwd(String password, String value) {
|
|
|
|
|
|
|
|
PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor();
|
|
|
|
|
|
|
|
encryptOr.setConfig(cryptOr(password));
|
|
|
|
|
|
|
|
String result = encryptOr.encrypt(value);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
encryptionDataSource(dataSource);
|
|
|
|
* 解密
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
|
|
|
|
|
|
|
|
* @param value 待解密密文
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String decryptPwd(String password, String value) {
|
|
|
|
|
|
|
|
PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor();
|
|
|
|
|
|
|
|
encryptOr.setConfig(cryptOr(password));
|
|
|
|
|
|
|
|
String result = encryptOr.decrypt(value);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param password salt
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static SimpleStringPBEConfig cryptOr(String password) {
|
|
|
|
|
|
|
|
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
|
|
|
|
|
|
|
config.setPassword(password);
|
|
|
|
|
|
|
|
// config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
|
|
|
|
|
|
|
|
// config.setKeyObtentionIterations("1000");
|
|
|
|
|
|
|
|
config.setPoolSize("1");
|
|
|
|
|
|
|
|
// config.setProviderName(null);
|
|
|
|
|
|
|
|
// config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
|
|
|
|
|
|
|
// config.setStringOutputType("base64");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
// HashMap<String, String> dataSource2 = MapUtil.newHashMap();
|
|
|
|
}
|
|
|
|
// dataSource2.put("url","xvrY1Lb+8pSI993YLonk0/Zc5UJJyrCEvobsCWPKzjhFyN5+6TxFksonriogCXk3ZZKdLZ2RuGlNZ/F4ezeZtDH/gYdGpYmRmGPHJfCGDXZIHUQAdqB5xIGYxdym4UkMhvxY0zH+LfECaL4Xh4SsbYnoEe0+YlRav24x/1cNW7ZxZ+5kXLc8wRTkSTUCmEOqwBrwVII5lhNBbBva/ItLqYSFdfdyLX2g3BYBUz2iSlqH2aMH2sjUnHaaeEqpSoLq");
|
|
|
|
|
|
|
|
// dataSource2.put("username","RZvKwBufVgR5YDlJ2ncYeWgaFIZ92BpKnepqv6EuUMFz1FY7rIyJEJyhR/NYYN7F");
|
|
|
|
|
|
|
|
// dataSource2.put("password","ixlE6Xon2PkZGz2YWT30XodveKEhidgo3m2QWrzT9Wf9Jh5tTs/MKxEXZJPBSvij");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// decryptDataSource(dataSource2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
|
|
|
|
|
|
|
|
// standardPBEStringEncryptor.setPassword("aa78fcbe21d77af8");
|
|
|
|
|
|
|
|
// System.out.println(standardPBEStringEncryptor.decrypt("I41o92myZEH//IF94wRL63p1fYXvq+OaltRqSCk4OhzT3Ff5G4aj4Y8URNzarpiM"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 打印密钥和加密串
|
|
|
|
* 打印密钥和加密串
|
|
|
@ -95,7 +73,6 @@ public class jasyptEncryptUtils {
|
|
|
|
String url = encryptPwd(key,dataSource.get("url"));
|
|
|
|
String url = encryptPwd(key,dataSource.get("url"));
|
|
|
|
String username = encryptPwd(key,dataSource.get("username"));
|
|
|
|
String username = encryptPwd(key,dataSource.get("username"));
|
|
|
|
String password = encryptPwd(key,dataSource.get("password"));
|
|
|
|
String password = encryptPwd(key,dataSource.get("password"));
|
|
|
|
|
|
|
|
|
|
|
|
//保存在目录下
|
|
|
|
//保存在目录下
|
|
|
|
FileWriter writer = new FileWriter(new File(FILE_PATCH_ALL), CHARSET_UTF8);
|
|
|
|
FileWriter writer = new FileWriter(new File(FILE_PATCH_ALL), CHARSET_UTF8);
|
|
|
|
writer.write("key: "+ key + LINE,false);
|
|
|
|
writer.write("key: "+ key + LINE,false);
|
|
|
@ -104,22 +81,43 @@ public class jasyptEncryptUtils {
|
|
|
|
writer.write("password: " + PREFIX +password + SUFFIX + LINE,true);
|
|
|
|
writer.write("password: " + PREFIX +password + SUFFIX + LINE,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Jasypt生成加密结果
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
|
|
|
|
|
|
|
|
* @param value 待加密值
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String encryptPwd(String password, String value) {
|
|
|
|
|
|
|
|
PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor();
|
|
|
|
|
|
|
|
encryptOr.setConfig(cryptOr(password));
|
|
|
|
|
|
|
|
String result = encryptOr.encrypt(value);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
/**
|
|
|
|
HashMap<String, String> dataSource = MapUtil.newHashMap();
|
|
|
|
* 解密
|
|
|
|
dataSource.put("url","jdbc:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
|
|
|
*
|
|
|
|
dataSource.put("username","nacos");
|
|
|
|
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
|
|
|
|
dataSource.put("password","nacos2233");
|
|
|
|
* @param value 待解密密文
|
|
|
|
|
|
|
|
* @return
|
|
|
|
encryptionDataSource(dataSource);
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String decryptPwd(String password, String value) {
|
|
|
|
|
|
|
|
PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor();
|
|
|
|
/* HashMap<String, String> dataSource2 = MapUtil.newHashMap();
|
|
|
|
encryptOr.setConfig(cryptOr(password));
|
|
|
|
dataSource2.put("url","tdAxOXA3+S2kSy2Rv8sfFujgdl46zQy+Cl7xVnC9pDhZrVwtHnCdOeco2zkvyZnMDfIl/uiBig3DYmU4HqGbQgwBeYdyqamHu9jGKxVI9RzlKVM4XiDae630G5hSwNzhndchz33PBUZ0IMdvB7pDcDs/Ug/5h8O47qQ0TQrTAOarKOFkZCoA7wNqaDhYJmZzTCAtvPadRx8qdNRKHsbswFtjqmCO+QrW");
|
|
|
|
String result = encryptOr.decrypt(value);
|
|
|
|
dataSource2.put("username","ghFv/J1tegsx6a/kVdzwVQ==");
|
|
|
|
return result;
|
|
|
|
dataSource2.put("password","VNMRcA303/pklpGem3JQYP8T+GwZXwnC");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decryptDataSource(dataSource2);*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param password salt
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static SimpleStringPBEConfig cryptOr(String password) {
|
|
|
|
|
|
|
|
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
|
|
|
|
|
|
|
config.setPassword(password);
|
|
|
|
|
|
|
|
config.setAlgorithm("PBEWithMD5AndDES");
|
|
|
|
|
|
|
|
config.setPoolSize("1");
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|