Jasypt 实现 yml 配置加密


前言

jasypt 官方地址:https://github.com/ulisesbocchio/jasypt-spring-boot

Jasypt可以为Springboot加密的信息很多,主要有:

  1. System Property 系统变量。
  2. Envirnment Property 环境变量。
  3. Command Line argument 命令行参数。
  4. Application.properties 应用配置文件。
  5. Yaml properties 应用配置文件。
  6. other custom property sources 其它配置文件。

一、集成 Jasypt

1. pom 依赖

<!-- jasypt(yml加密) -->
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>3.0.5</version>
</dependency>

2. yml 依赖

jasypt:
  encryptor:
    password: encpassword # 加密盐值(自定义)
    algorithm: PBEWithMD5AndDES # 加密算法(3.0.5以下版本默认PBEWithMD5AndDES,即DES加密算法-32位密文;3.0.5及以上版本默认PBEWITHHMACSHA512ANDAES_256,即AES加密算法-64位密文)
    iv-generator-classname: org.jasypt.iv.NoIvGenerator # 加密偏移生成器

3. 加密工具类

使用如下工具类,对密码进行加密获取密文。

import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

/**
 * jasypt(yml加密)工具
 *
 * @author whiteen
 * @date 2024-06-20 00:00:00
 */
@Slf4j
public class JasyptUtil {
   
   

    /**
     * DES加密
     *
     * @param original 待加密内容
     * @param password 加密盐值
     * @return 加密密文
     * @author whiteen
     * @date 2024-06-20 00:00:00
     */
    public static String encryptByDes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Whitemeen太白

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

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

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

打赏作者

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

抵扣说明:

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

余额充值