1.相关依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
2.配置到properties文件或者yml文件上
#自定义 加密因子
jasypt.encryptor.password = ALK9382LDF234UIJ79GJ0F
#官方默认的加密算法是 PBEWITHHMACSHA512ANDAES_256 但是如果用的是jdk1.8 不支持,需要改成 PBEWithMD5AndDES
jasypt.encryptor.algorithm = PBEWITHHMACSHA512ANDAES_256
# 配置格式(不写默认ENC)前后缀
jasypt.encryptor.property.prefix= ENC[
jasypt.encryptor.property.suffix= ]
jasypt:
encryptor:
#自定义 加密因子。随便写
password: ALK9382LDF234UIJ79GJ0F5HD
# 官方默认的加密算法是 PBEWITHHMACSHA512ANDAES_256 但是如果用的是jdk1.8 不支持需要改成 PBEWithMD5AndDES
algorithm: PBEWithMD5AndDES
# 配置格式(不写默认ENC)
property:
prefix: ENC[
suffix: ]
3.测试,获取加密后的密码
4.配置到nacos上properties文件形式,也可以yml文件上只是格式换成yml格式,
5.服务启动类上添加@EnableEncryptableProperties
@EnableEncryptableProperties
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(BusinessApplication.class, args); }
}