springboot#配置文件密码加密
jasypt(静安寺云平台) 实现了 ApplicationContextInitializer 接口,重写了获取环境变量的方法,在容器初始化时对配置文件中的属性进行判断,若包类似"ENC(xxxx)"属性值,则进行解密并返回。
1.引入maven依赖:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
2.指定加密属性的密钥(password),并对实际密码进行加密(input):
java -cp jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="this_is_password" password="hello_kitty" algorithm=PBEWithMD5AndDES
3.配置用于加密属性的密钥,以及使用生成好的密码(通过ENC()包裹)
jasypt.encryptor.password=hello_kitty
mysql.spring.datasource.password=ENC(SqFjGqx/YqnnBJrefEj8dp6qz525ERKVGslRQ5bEQdU=)