admin管理员组文章数量:1530085
1.SpringBoot项目pom添加maven依赖
<!-- https://mvnrepository/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter --> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.5</version> </dependency>
2.使用单元测试生成加密数据
设置配置文件(bootstrap.yml或者application.yml)
jasypt: encryptor: password: jasypt!di@soc algorithm: PBEWithMD5AndDES
password:加密的盐
algorithm:加密算法,这里使用 PBEWithMD5AndDES
运行单元测试文件
package com.pscsoft.code.isoc; import org.jasypt.encryption.StringEncryptor; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; /** * @author avry.jiang * @date 2023-06-28 17:45:58 */ @SpringBootTest() @Import({IsocApplication.class}) public class JasyptUtilTest { @Autowired private StringEncryptor encryptor; @Test public void jasypt() { String name = encryptor.encrypt("12345678"); System.out.println("en: " + name); System.out.println("de: " + encryptor.decrypt(name)); } }
执行结果:
3.在SpringBoot项目中使用
配置mysql的jdbc,使用“ENC(密文)”配置密码,其他配置有密码都类似修改
4.将加密盐放入配置文件、启动环境或者启动命令中
4.1.Idea启动项配置
--jasypt.encryptor.password=jasypt!di@soc --jasypt.encryptor.algorithm=PBEWithMD5AndDES
4.2.配置文件(不推荐,会暴露加密盐反推明文的)
jasypt: encryptor: password: jasypt!di@soc algorithm: PBEWithMD5AndDES
4.3.其他
如果是docker启动,可以配置在Dockerfile中指定启动命令
ENTRYPOINT ["java","-jar","-Xms1024m", "-Xmx1024m","--jasypt.encryptor.password=jasypt!di@soc","--jasypt.encryptor.algorithm=PBEWithMD5AndDES", "/xxx/xxx.jar"]
启动项目即可
本文标签: 配置文件项目SpringBoot
版权声明:本文标题:对SpringBoot项目配置文件进行加密 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726164751a1058102.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论