REM:
1. 增加配置文件加密库
This commit is contained in:
HuangXin 2020-09-16 14:35:41 +08:00
parent 163432d68c
commit 9655807e61
4 changed files with 77 additions and 0 deletions

View File

@ -207,6 +207,11 @@
<version>20.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
<build>

View File

@ -1,5 +1,6 @@
package com.dispose;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
@ -19,6 +20,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableScheduling
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableEncryptableProperties
@MapperScan(basePackages = {"com.dispose.mapper"})
@Slf4j
public class PhoenixBootApplication {

View File

@ -0,0 +1,36 @@
package com.dispose.interceptor;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
/**
* The type Config security interceptor.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
public class ConfigSecurityInterceptor {
/**
* String encryptor string encryptor.
*
* @return the string encryptor
*/
@Bean("jasyptStringEncryptor")
static public StringEncryptor stringEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword("xajhuang");
config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName("SunJCE");
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
return encryptor;
}
}

View File

@ -0,0 +1,34 @@
package com.dispose.test.dev.function;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableEncryptableProperties
@Configuration
@Slf4j
public class CryptoConfigureFile {
@Resource
private StringEncryptor encryptor;
@Test
public void t1_jasyptEncrypt() {
String srcTest = "root";
String enText = encryptor.encrypt(srcTest);
String deTest = encryptor.decrypt(enText);
log.info("Src: {}", srcTest);
log.info("Encrypt: {}", enText);
log.info("Decrypt: {}", deTest);
}
}