Jasypt加密yml配置

0 引入jar包

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

1 启动类添加配置

添加@EnableEncryptableProperties

@EnableEncryptableProperties
public class AdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(AdminApplication.class, args);
    }
}

2 yml添加jasypt配置

jasypt:
  encryptor:
    # 加密密钥
    password: 123456789
    # 加密算法
    algorithm: PBEWithMD5AndDES
    iv-generator-classname: org.jasypt.iv.NoIvGenerator
    # 算法识别的前后缀,可自定义
#    property:
#      prefix: ENC(
#      suffix: )

3 加解密

public static void main(String[] args) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
    config.setPassword("123456789");
    encryptor.setConfig(config);
    String encrypt = encryptor.encrypt("123456");
    System.out.println(encrypt); // 加密
    System.out.println(encryptor.decrypt(encrypt)); // 解密
}

4 修改明文配置

spring:
  datasource:
    druid:
      master:
        url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEnco
        username: test
        password: ENC(DxddShHUvjWkAHax2QBuvQ==)

5 不在配置文件中配置jasypt的加密密钥

5.1 iDea中测试

-Djasypt.encryptor.password=123456789
在这里插入图片描述

5.2 打包部署项目

① java -jar xxx.jar -Djasypt.encryptor.password=加密数据的秘钥
② java -jar xxx.jar --jasypt.encryptor.password=加密数据的秘钥

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值