1.pom.xml
<!-- 配置项加密组件-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
2.配置文件
jasypt.encryptor.password=abcdef
3.加密解密
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
/**
* @Description TODO
* @Author kongweixin
* @Date $ $
**/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ProviderApplication.class)
@WebAppConfiguration
@Slf4j
public class OrderTest {
@Autowired
private StringEncryptor stringEncryptor;
@Test
public void contextLoads() {
//加密方法
System.out.println(stringEncryptor.encrypt("123456"));
//解密方法
System.out.println(stringEncryptor.decrypt("KglELGVZTtkhvcIhIQgOqmGJgD1CENnU"));
}
}