2024-1-19 更新。
后续代码又提交了一次,对配置文件中jasypt:encryptor:password: 97ade351f6cf4b9e再次扫描出明文密码漏洞!!!!!仿佛被套娃!!!
本次更新的5、6、7 如果没有后续就是解决掉问题了。
java -jar -Djasypt.encryptor.password=123456 springboot-jasypt-test.jar
1、首先引入依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
2、yml文件中添加密钥
jasypt:
encryptor:
password: 97ade351f6cf4b9e //自己随便设置的密钥
3、加密、解密方法
@Autowired
private StringEncryptor stringEncryptor;
// 加密
stringEncryptor.encrypt("root");
// 解密
stringEncryptor.decrypt(stringEncryptor.encrypt("root"));
也可以使用System.out.println(),直接输出结果
4、 修改yml文件中配置的密码(需要用 ENC() )
password: ENC(加密后的密码)
5、在去除配置文件中jasypt:encryptor:password: 97ade351f6cf4b9e,改为启动参数
在idea配置好后,就可以正常启动了
6、idea配置好后,发现部署打包又失败,所以给maven加配置
7、 最后不要忘记 启动时 加上参数
java -jar -Djasypt.encryptor.password=97ade351f6cf4b9e system-test.jar
防止后期找不到,忘记了,自己写了一遍存起来