【Java】Ruoyi-Vue-Plus 整合 jasypt 为SpringBoot配置文件进行加密

本文介绍了如何在Ruoyi-Vue-Plus项目中使用jasypt进行配置文件参数加密,包括在pom.xml中添加依赖、在application.yml中配置加密参数,以及如何创建一个加密工具类进行URL、用户名和密码的加密与解密。还讨论了如何通过JVM启动参数保护密钥的安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开发环境

  • 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_256saltGeneratorClassname默认值是org.jasypt.salt.RandomSaltGeneratorproperty中的默认前后缀为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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值