新增jasypt.jar 对配置文件中的账号密码进行加密
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
###### v2.2.0
|
||||
- update-20220727-fuqj:修改获取人员信息逻辑,把从山分查询出来的人员通过extend服务扩展覆盖后的信息,缓存到本地redis中。
|
||||
- update-20220907-fuqj:修改通过userinfo服务查询,同时添加mongodb使用的businessModule
|
||||
- add-20220923-fuqj: 新增jasypt.jar 对配置文件中的账号密码进行加密 `JasyptStarterConfiguration`
|
||||
|
||||
|
||||
|
||||
|
@ -180,6 +180,12 @@
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-data-mongodb</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- jasypt -->
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.jasypt.starter;
|
||||
|
||||
|
||||
import org.jasypt.encryption.StringEncryptor;
|
||||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
||||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class JasyptStarterConfiguration {
|
||||
|
||||
@Bean( name = "stringEncryptor" )
|
||||
public StringEncryptor stringEncryptor() {
|
||||
|
||||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
||||
|
||||
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
||||
config.setPassword("uniom-ebtp");
|
||||
config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
|
||||
config.setKeyObtentionIterations("1000");
|
||||
config.setPoolSize("1");
|
||||
config.setProviderName("SunJCE");
|
||||
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
||||
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
|
||||
config.setStringOutputType("base64");
|
||||
encryptor.setConfig(config);
|
||||
|
||||
return encryptor;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.jasypt.starter.util;
|
||||
|
||||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
||||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
|
||||
|
||||
public class JasyptUtil {
|
||||
|
||||
|
||||
public static String encryptStr(String encryptStr, String password) {
|
||||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
||||
|
||||
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
||||
config.setPassword(password);
|
||||
config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
|
||||
config.setKeyObtentionIterations("1000");
|
||||
config.setPoolSize("1");
|
||||
config.setProviderName("SunJCE");
|
||||
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
||||
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
|
||||
config.setStringOutputType("base64");
|
||||
encryptor.setConfig(config);
|
||||
|
||||
String enPw = encryptor.encrypt(encryptStr);
|
||||
System.out.println("加密后:" + enPw);
|
||||
String decrypt = encryptor.decrypt(enPw);
|
||||
System.out.println("解密的字符串:" + decrypt);
|
||||
return enPw;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JasyptUtil.encryptStr("Eshop@2021","uniom-ebtp");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user