fix:解决jasypt导入报错:
1.配置生成的密码未去除双引号 2.生成秘钥的配置不宜过多有些奇怪bug,jasypt是由热插拔形式代理原来springboot的mvc模块的org.springframework.core.env.MapPropertySource
This commit is contained in:
parent
ce06053b34
commit
a7b7836523
|
|
@ -14,20 +14,20 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class jasyptHandler {
|
public class jasyptHandler {
|
||||||
|
|
||||||
@Bean("jasyptStringEncryptor")
|
// @Bean("jasyptStringEncryptor")
|
||||||
public StringEncryptor stringEncryptor() {
|
// public StringEncryptor stringEncryptor() {
|
||||||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
// PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
||||||
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
// SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
||||||
// 配置解析的密码
|
// // 配置解析的密码
|
||||||
config.setPassword("password");
|
// config.setPassword("password");
|
||||||
config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
|
// config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
|
||||||
config.setKeyObtentionIterations("1000");
|
// config.setKeyObtentionIterations("1000");
|
||||||
config.setPoolSize("1");
|
// config.setPoolSize("1");
|
||||||
// config.setProviderName("SunJCE");
|
//// config.setProviderName("SunJCE");
|
||||||
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
// config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
||||||
// config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
|
//// config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
|
||||||
config.setStringOutputType("base64");
|
// config.setStringOutputType("base64");
|
||||||
encryptor.setConfig(config);
|
// encryptor.setConfig(config);
|
||||||
return encryptor;
|
// return encryptor;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,6 +24,63 @@ 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) {
|
||||||
|
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");
|
||||||
|
dataSource.put("password","nacos2233");
|
||||||
|
|
||||||
|
encryptionDataSource(dataSource);
|
||||||
|
|
||||||
|
|
||||||
|
// 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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印密钥和加密串
|
||||||
|
* @param dataSource 集合
|
||||||
|
*/
|
||||||
|
public static void decryptDataSource(Map<String,String> dataSource){
|
||||||
|
String key = AESMybatisPlusUtils.genOrGetKey();
|
||||||
|
String url = decryptPwd(key,dataSource.get("url"));
|
||||||
|
String username = decryptPwd(key,dataSource.get("username"));
|
||||||
|
String password = decryptPwd(key,dataSource.get("password"));
|
||||||
|
|
||||||
|
//保存在目录下
|
||||||
|
FileWriter writer = new FileWriter(new File(FILE_PATCH_DE), CHARSET_UTF8);
|
||||||
|
writer.write("key: "+ key + LINE,false);
|
||||||
|
writer.write("url: " +url + LINE,true);
|
||||||
|
writer.write("username: " +username + LINE,true);
|
||||||
|
writer.write("password: " +password + LINE,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印密钥和加密串
|
||||||
|
* @param dataSource 集合
|
||||||
|
*/
|
||||||
|
public static void encryptionDataSource(Map<String,String> dataSource){
|
||||||
|
String key = AESMybatisPlusUtils.genOrGetKey();
|
||||||
|
String url = encryptPwd(key,dataSource.get("url"));
|
||||||
|
String username = encryptPwd(key,dataSource.get("username"));
|
||||||
|
String password = encryptPwd(key,dataSource.get("password"));
|
||||||
|
//保存在目录下
|
||||||
|
FileWriter writer = new FileWriter(new File(FILE_PATCH_ALL), CHARSET_UTF8);
|
||||||
|
writer.write("key: "+ key + LINE,false);
|
||||||
|
writer.write("url: " + PREFIX +url + SUFFIX + LINE,true);
|
||||||
|
writer.write("username: " + PREFIX +username + SUFFIX + LINE,true);
|
||||||
|
writer.write("password: " + PREFIX +password + SUFFIX + LINE,true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jasypt生成加密结果
|
* Jasypt生成加密结果
|
||||||
*
|
*
|
||||||
|
|
@ -58,68 +116,8 @@ public class jasyptEncryptUtils {
|
||||||
public static SimpleStringPBEConfig cryptOr(String password) {
|
public static SimpleStringPBEConfig cryptOr(String password) {
|
||||||
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
||||||
config.setPassword(password);
|
config.setPassword(password);
|
||||||
// config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
|
config.setAlgorithm("PBEWithMD5AndDES");
|
||||||
// config.setKeyObtentionIterations("1000");
|
|
||||||
config.setPoolSize("1");
|
config.setPoolSize("1");
|
||||||
// config.setProviderName(null);
|
|
||||||
// config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
|
||||||
// config.setStringOutputType("base64");
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印密钥和加密串
|
|
||||||
* @param dataSource 集合
|
|
||||||
*/
|
|
||||||
public static void decryptDataSource(Map<String,String> dataSource){
|
|
||||||
String key = AESMybatisPlusUtils.genOrGetKey();
|
|
||||||
String url = decryptPwd(key,dataSource.get("url"));
|
|
||||||
String username = decryptPwd(key,dataSource.get("username"));
|
|
||||||
String password = decryptPwd(key,dataSource.get("password"));
|
|
||||||
|
|
||||||
//保存在目录下
|
|
||||||
FileWriter writer = new FileWriter(new File(FILE_PATCH_DE), CHARSET_UTF8);
|
|
||||||
writer.write("key: "+ key + LINE,false);
|
|
||||||
writer.write("url: " +url + LINE,true);
|
|
||||||
writer.write("username: " +username + LINE,true);
|
|
||||||
writer.write("password: " +password + LINE,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印密钥和加密串
|
|
||||||
* @param dataSource 集合
|
|
||||||
*/
|
|
||||||
public static void encryptionDataSource(Map<String,String> dataSource){
|
|
||||||
String key = AESMybatisPlusUtils.genOrGetKey();
|
|
||||||
String url = encryptPwd(key,dataSource.get("url"));
|
|
||||||
String username = encryptPwd(key,dataSource.get("username"));
|
|
||||||
String password = encryptPwd(key,dataSource.get("password"));
|
|
||||||
|
|
||||||
//保存在目录下
|
|
||||||
FileWriter writer = new FileWriter(new File(FILE_PATCH_ALL), CHARSET_UTF8);
|
|
||||||
writer.write("key: "+ key + LINE,false);
|
|
||||||
writer.write("url: " + PREFIX +url + SUFFIX + LINE,true);
|
|
||||||
writer.write("username: " + PREFIX +username + SUFFIX + LINE,true);
|
|
||||||
writer.write("password: " + PREFIX +password + SUFFIX + LINE,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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");
|
|
||||||
dataSource.put("password","nacos2233");
|
|
||||||
|
|
||||||
encryptionDataSource(dataSource);
|
|
||||||
|
|
||||||
|
|
||||||
/* HashMap<String, String> dataSource2 = MapUtil.newHashMap();
|
|
||||||
dataSource2.put("url","tdAxOXA3+S2kSy2Rv8sfFujgdl46zQy+Cl7xVnC9pDhZrVwtHnCdOeco2zkvyZnMDfIl/uiBig3DYmU4HqGbQgwBeYdyqamHu9jGKxVI9RzlKVM4XiDae630G5hSwNzhndchz33PBUZ0IMdvB7pDcDs/Ug/5h8O47qQ0TQrTAOarKOFkZCoA7wNqaDhYJmZzTCAtvPadRx8qdNRKHsbswFtjqmCO+QrW");
|
|
||||||
dataSource2.put("username","ghFv/J1tegsx6a/kVdzwVQ==");
|
|
||||||
dataSource2.put("password","VNMRcA303/pklpGem3JQYP8T+GwZXwnC");
|
|
||||||
|
|
||||||
decryptDataSource(dataSource2);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
key: aa78fcbe21d77af8
|
key: aa78fcbe21d77af8
|
||||||
url: PINN@[RDvIMG8MFQAINuVwgI59BimaqgkEOrcnY0vj8kYmZMmlRWwl+9rn7weZDNwon807LaYXZF+hme4/+Ye4d9LwHUS2IzOvz/nOqXoeqmPIMYNq2Cdt4AAIvtENj+Fnp4/XccSKfhAlA8pRarc/lk8F7l62ul5VsxKi8lUQatXDB1v1OCsNAzDowj2l7T0o/TzNrIHWl0b9yYcZZVGDnyYrkA==]
|
url: PINN@[b43OeNppIVyLnbWEybBFR7ilgcIOkQz5Mkb2tWtOuugrQoTxjpf3hozwU8LRSpboCAOf4WSAB9eknmbS15qX42/e6g1XmmJCsSAwx3TswOjX9x6BgjcDiWrUcYx4ZiNS9wO79ieCkLdeWRW1AZ6msuFV0JGRQNMpsLaJjwra2BZ4Hldq88EDjyZntBvT2s58EXM/bjMKIQhynkUibEbAhw==]
|
||||||
username: PINN@[9LFA4aI0xDSxwlsyyoJf1w==]
|
username: PINN@[WEciwJ1eT6ZjAMncoppuow==]
|
||||||
password: PINN@[AG6wLP/NWZx1UpBDYIHAcpQ62kjD7mfa]
|
password: PINN@[YZXfQ+pMtdFaMCxbKy5ey5BfxIG2RQnZ]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
key: aa78fcbe21d77af8
|
key: aa78fcbe21d77af8
|
||||||
url: 'jdbc:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8'
|
url: jdbc:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
username: 'nacos'
|
username: nacos
|
||||||
password: 'nacos2233'
|
password: nacos2233
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue