前言
jasypt 官方地址:https://github.com/ulisesbocchio/jasypt-spring-boot
Jasypt可以为Springboot加密的信息很多,主要有:
- System Property 系统变量。
- Envirnment Property 环境变量。
- Command Line argument 命令行参数。
- Application.properties 应用配置文件。
- Yaml properties 应用配置文件。
- 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

最低0.47元/天 解锁文章
2769

被折叠的 条评论
为什么被折叠?



