springboot配置文件中的敏感信息加密

加上依赖

        <!-- 保护springboot配置文件加密-->
        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>

配置

# jasypt加密的密匙
jasypt:
  encryptor:
    password: Y6M9fAJQdU7jNp5MW
package springboot.test;

import org.jasypt.encryption.StringEncryptor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author cruder
 * @since 2021/9/17
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class DatabaseTest {

    @Autowired
    private StringEncryptor encryptor;

    @Test
    public void getPass() {
        String url = encryptor.encrypt("jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8");
        String name = encryptor.encrypt("root");
        String password = encryptor.encrypt("123456");
        System.out.println("url: " + url);
        System.out.println("username: " + name);
        System.out.println("password: " + password);
        Assert.assertTrue(url.length() > 0);
        Assert.assertTrue(name.length() > 0);
        Assert.assertTrue(password.length() > 0);
    }
}
conlose输出:
url: f0cuu4F0E5JveF6VbBzF4L8JVlPhDiUAKRauQAMvO71ZdHO8jbFcy39EKGoMQgoc6iOBQY1Fe2h166paeDuMxICoobyZS+oFU36bTh8GUlJJgcItFCohNNaWl5Lv+tzN
username: w70pSwXkQpiwDvRRvUfHIQ==
password: NqMKAVdTDda7rVDdIIKPsg==

把配置文件对应部分改了
在这里插入图片描述
然后发现居然能正常启动,
盐巴是放在配置文件里的不安全,
为了防止salt(盐)泄露,反解出密码.可以在项目部署的时候使用命令传入salt(盐)

java -jar xxx.jar  -Djasypt.encryptor.password=Y6M9fAJQdU7jNp5MW
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值