jasypt与Spring结合使用解决配置文件中数据库密码加密问题

本文介绍了如何使用jasypt与Spring结合,解决配置文件中数据库密码明文显示的问题。通过在pom.xml添加依赖,配置spring.xml,修改properties文件并使用特定的加密算法和秘钥生成密文,以及探讨了秘钥的安全配置方法,包括环境变量、直接配置和properties文件方式。
摘要由CSDN通过智能技术生成

引言

最近公司给银行做了一个项目,在进行本地化部署的时候,银行的科技部门对我们的源码进行了安全扫描,在检测报告中有这么一个问题,要求我们的数据库密码不能以明文的 形式出现在配置文件中,所以小编需要解决这个问题,但是第一个想法就是,自己重写一个配置文件加载的那个方法,这样我们就可以在拿到密文以后,首先解密然后在使用。

但是查询了一些资料以后发现,这个问题已经有成熟的解决方案了,就是利用jasypt与spring结合轻松解决这个问题。

1、首先在项目中pom.xml文件中加入jasypt相关依赖包


<dependency>
    <groupId>org.jasypt</groupId>
    <artifactId>jasypt</artifactId>
<version>1.9.2</version>

2、在spring的xml文件中增加配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--基于环境变量,配置加密机-->
    <bean id="environmentVariablesConfiguration"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

g-Jack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值