SpringBoot实现数据库密码的加密操作

<!-- 开启数据库加密 -->
<!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.5-java7</version>

</dependency>

 通过dos执行如下命令:java -cp  D:\maven_repository\org\jasypt\jasypt\1.9.2\jasypt-1.9.2.jar  org.jasypt.intf.cli.JasyptPBEStringEncryptionCLIinput="123456" password=e9fbdb2d3b21 algorithm=PBEWithMD5AndDES

其中标红部分为需要加密的部分,password为加密需要的salt值,algorithm为加密算法

执行上面的命令后会出现如下内容,其中OUTPUT部分为加密后的内容

SpringBoot实现数据库密码的加密操作

配置文件中需要配置两个地方:

#加密使用的salt值
jasypt.encryptor.password=e9fbdb2d3b21

通过ENC进行密码解密操作

spring.datasource.password=ENC(uKPcUQufY8pCArG9T+x+SA==)