新增jasypt.jar 对配置文件中的账号密码进行加密

This commit is contained in:
fuqingji
2022-09-23 15:11:08 +08:00
parent 550bd66d20
commit c4e5b7a830
4 changed files with 74 additions and 0 deletions

View File

@ -17,6 +17,7 @@
###### v2.2.0 ###### v2.2.0
- update-20220727-fuqj修改获取人员信息逻辑把从山分查询出来的人员通过extend服务扩展覆盖后的信息缓存到本地redis中。![img.png](resource/user_auth_process.png) - update-20220727-fuqj修改获取人员信息逻辑把从山分查询出来的人员通过extend服务扩展覆盖后的信息缓存到本地redis中。![img.png](resource/user_auth_process.png)
- update-20220907-fuqj修改通过userinfo服务查询同时添加mongodb使用的businessModule - update-20220907-fuqj修改通过userinfo服务查询同时添加mongodb使用的businessModule
- add-20220923-fuqj: 新增jasypt.jar 对配置文件中的账号密码进行加密 `JasyptStarterConfiguration`

View File

@ -180,6 +180,12 @@
<!-- <groupId>org.springframework.boot</groupId>--> <!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-mongodb</artifactId>--> <!-- <artifactId>spring-boot-starter-data-mongodb</artifactId>-->
<!-- </dependency>--> <!-- </dependency>-->
<!-- jasypt -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies> </dependencies>

View File

@ -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;
}
}

View File

@ -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");
}
}