在 Spring Boot 3 中,可以通过`jasypt-spring-boot-starter`对配置文件中的数据库密码或者其他重要密码进行加密,操作非常简单,可以有效防止密码泄露:

1. 使用 Jasypt 加密
添加依赖
在 pom.xml 中添加 Jasypt 依赖:
jasypt-spring-boot-starter http:// https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter
http:// https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter
<!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter -->
<!-- https://zhengkai.blog.csdn.net/ -->
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>3.0.5</version>
</dependency>
加密密码
使用 Jasypt 提供的工具对密码进行加密:
java -cp jasypt-spring-boot-cli-3.0.5.jar com.ulisesbocchio.jasyptspringboot.cli.EncryptorCLI input="yourPassword" password="encryptionKey"
请注意保存好你的encryptionKey和password
- input="yourPassword"
- password="encryptionKey"
 
这将输出一个加密的密码,例如:ENC(encryptedPassword)
配置文件设置
在 application.properties 或 application.yml 中使用加密后的密码:
#by https://zhengkai.blog.csdn.net/
spring.datasource.url=jdbc:mysql://localhost:3306/yourdb
spring.datasource.username=yourUsername
spring.datasource.password=ENC(encryptedPassword)配置解密
在 application.properties 中添加解密密钥:
jasypt.encryptor.password=encryptionKey#https://zhengkai.blog.csdn.net/
#encryptedPassword
spring:
    datasource:
      type: com.alibaba.druid.pool.DruidDataSource
      driverClassName: org.postgresql.Driver
      url: jdbc:postgresql://127.0.0.1:5432/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
      username: postgres
      password: ENC(encryptedPassword)
#encryptionKey
jasypt:
    encryptor:
        password: encryptionKey通过使用 Jasypt 或其他秘密管理工具,可以有效地保护 Spring Boot 应用程序中的敏感信息。选择适合你的应用场景的加密策略,确保密码等敏感数据的安全。
















![三六零[601360]行情数据接口](https://i-blog.csdnimg.cn/direct/4ec342674adf4982b463a8427ab9008e.png)


