spring boot项目通过jasypt-spring-boot-starter加密配置Demo
https://blog.csdn.net/longe8000/article/details/887503231. pom.xml增加jasypt-spring-boot-starter依赖<dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring
https://blog.csdn.net/longe8000/article/details/88750323
1. pom.xml增加jasypt-spring-boot-starter依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
2.application.properties使用加密了的配置
test.datasource.username=ENC(MncHf2ANrI7ecelmdnHmzg==)
test.datasource.password=ENC(vQPa96fd5XhDzpj2ktHRvQ==)
注:红色为密文
3.配置密码
可配置在application.properties文件中(这种方式不安全)
jasypt.encryptor.password=123456
在JVM启动参数中设置
-Djasypt.encryptor.password=123456
附:生成密文的工具代码
package com.example.demo;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
public class EncryptConfigUtil {
public static void main(String[] args) {
String password = "123456";
String data = "root";
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword(password);
config.setAlgorithm("PBEWithMD5AndDES");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName(null);
config.setProviderClassName(null);
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setIvGeneratorClassName("org.jasypt.salt.NoOpIVGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
System.out.println(encryptor.encrypt(data));
}
}
————————————————
版权声明:本文为CSDN博主「longe8000」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/longe8000/article/details/88750323
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)