开发环境
- Ruoyi-Vue-Plus 5.1.2(Spring Boot 3.1.7)
- jasypt 3.0.5
引入依赖
项目的根pom.xml
项目的根 pom.xml 文件中,添加同一版本管理
<properties>
<!--配置文件参数加密-->
<jasypt.version>3.0.5</jasypt.version>
</properties>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- 其他依赖配置 -->
<!--配置文件参数加密-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>${jasypt.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
ruoyi-admin 模块的 pom.xml
ruoyi-admin 模块的 pom.xml 中引入依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
</dependency>
application.yml 配置
注意:如果在 application.yml 中没有配置对应的属性,将使用默认值,比如algorithm默认值为PBEWITHHMACSHA512ANDAES_256,saltGeneratorClassname默认值是org.jasypt.salt.RandomSaltGenerator,property中的默认前后缀为ENC( 和 ) 等。
在 ruoyi-admin 模块的 application.yml 文件中配置如下:
--- # jasypt 配置(这是JDK17下的配置)
jasypt:
encryptor:
# 加密的秘钥
password: abc123456
# 加密算法 jasypt3.0后,默认算法为 PBEWITHHMACSHA512ANDAES_256,需要JDK9以上或者 添加JCE(Java Cryptography Extension 无限强度权限策略文件)支持
algorithm: PBEWITHHMACSHA512ANDAES_256
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
property