pomjava
com.github.ulisesbocchiojasypt-spring-boot-starter2.1.0
配置密钥git
配置文件添加 jasypt.encryptor.password: demo
获取密文github
//若是有多个配置文件,可用经过ActiveProfiles来指定配置文件;将匹配到配置文件:application-18011.properties @ActiveProfiles("18011") @SpringBootTest(classes = DemoApplication.class) public class PigAdminApplicationTest { //从spring环境中获取bean,这个bean是从哪里来的呢?jasypt的starter @Autowired private StringEncryptor stringEncryptor; @Test public void testEnvironmentProperties() { //将明文加密 System.out.println(stringEncryptor.encrypt("root")); System.out.println(stringEncryptor.encrypt("123456")); //解密 System.out.println(stringEncryptor.decrypt("bsK6LoI1XJrAFvynypY2Og==")); } }
在配置文件中使用算法
spring.datasource.username=ENC(PquhbjSL8UlUCK91LvuJNg==) spring.datasource.password=ENC(8r2VooGyAOd+Q2+FpgHu8Q==)
springboot启动时,几经经过密钥将密文解密,因此密钥将称为破译关键,因此须要:
java -jar xxx.jar --jasypt.encryptor.password=xxx
将密钥从项目中移除spring
更安全方案安全
1.拥有一个配置中心 2.配置中心有高度保密的配置文件 3.各项目向中心注册公钥,加密传输 4。项目内部经过私钥解密
jasypt.encryptor.password: demo缺失springboot
java.lang.IllegalStateException: Required Encryption configuration property missing: jasypt.encryptor.password