parent
163432d68c
commit
9655807e61
5
pom.xml
5
pom.xml
|
@ -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>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue