1.首先,添加jasypt依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
2.然后win+r,cmd调出窗口,添加加密指令
java -cp E:\Softeare\apache-maven-3.6.0\repository\org\jasypt\jasypt\1.9.2\jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="root" password=123456 algorithm=PBEWithMD5AndDES
3.在yml文件中添加jasypt密钥
jasypt:
encryptor:
password: 123456
4.将数据库密码修改成ENC(fBKD1fUlxJhw4PqWuh5oQQ==)(fBKD1fUlxJhw4PqWuh5oQQ==是加密后的密码),添加ENC()可以自动解密。
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url:
username: ${DATASOURCE_USERNAME}
password: ENC(fBKD1fUlxJhw4PqWuh5oQQ==)