使用jasypt 进行数据库配置加密

1.pom文件引入依赖

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>3.0.4</version>
        </dependency>

2.在application.yml中增加配置

jasypt:
  encryptor:
    algorithm: PBEWithMD5AndDES
    iv-generator-classname: org.jasypt.iv.NoIvGenerator

3.生成加密后的密文

    public static void main(String[] args) {
        BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
        //加密所需的salt
        textEncryptor.setPassword("123456");
        //要加密的数据(数据库的用户名或密码)
        String url = textEncryptor.encrypt("XXX");
        String username = textEncryptor.encrypt("XXX");
        String password = textEncryptor.encrypt("XXX");
        System.out.println("url:"+url);
        System.out.println("username:"+username);
        System.out.println("password:"+password);
    }

4.替换掉原来的数据库配置

jdbcUrl: ENC(XXX)
username: ENC(XXX)
password: ENC(XXX)

5.启动项目时增加配置

在idea中启动增加环境配置 -Djasypt.encryptor.password=123456

在服务器上通过java -jar方式启动,增加--jasypt.encryptor.password=123456

docker方式启动,修改Dockerfile文件,增加"-Djasypt.encryptor.password=123456"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值