Spring Boot下集成Jasypt对配置文件进行加密
2018-11-12 10:26
781 查看
由于日趋紧张的代码安全问题,更多的项目需要进行简单的加密措施。包括对数据库连接信息,redis连接信息等。
本文就讲解一下怎么使用Jasypt进行简单的配置文件加密。
一、在maven里添加Jasypt的依赖。
[code] <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency>
此处添加的Jasypt的version为2.0.0低于该版本的话可能会造成异常。
二、选择自己的PASSWORD(密钥)
[code]jasypt: encryptor: password: HelloWorld
对于密钥的选取大可按照自己的意思来但也不要过于简单,此处为了方便演示直接写在了配置文件之中。当然真正的项目当中是不能这么干的,不然其他的配置属性加密了但是你的密钥赤裸裸的放在这里那可就真的是愚不可及了。
所以面对这样的情况我们还有的办法就是启动项目的时候指定密钥:
[code]java -Djasypt.encryptor.password=HelloWorld -jar xxx.jar
三、将配置文件中的账号密码进行加密
此处需要到我们编写个简单的test来获取加密之后的信息:
[code] @Test public void encryptTest() { String result = stringEncryptor.encrypt("testHelloWorkd"); System.out.println(result); }
出现了问题?别忘了写Autowired。
[code] @Autowired StringEncryptor stringEncryptor;
假设运行后出现的密文为:xxxxxxxxxxxxx,然后将这个输出的结果放置到配置文件中即可,此处需要添加到ENC()中。
[code] username: test password: ENC(xxxxxxxxxxxxxx)
除了密码之后账户之类的信息只要你喜欢都可以进行加密。
阅读更多相关文章推荐
- Jasypt : 整合spring boot加密应用配置文件敏感信息
- 利用Jasypt如何对Spring Boot配置文件加密
- SpringBoot中加密包对配置文件中的密码进行加密
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- Spring Boot: 加密应用配置文件敏感信息
- Spring Boot: 加密应用配置文件敏感信息
- 在spring-config文件中对jdbc数据配置进行加密处理
- spring-boot集成mybatis问题1:IntellijIdea中j解决自动生成代码xml配置文件中出现“uri is not registered”问题
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- SpringBoot之Mybatis连接MySQL进行CRUD(注解&配置文件)(简测试版)
- jasypt 集成spring、spring boot 加密
- 使用Jasypt对数据库配置文件进行加密
- 4 springboot项目集成使用disconf,配置文件更新及回调
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- Spring Boot学习笔记----读取配置文件
- SpringBoot自定义配置文件路径
- Spring boot 集成工作流flowable去掉xml配置
- Spring Boot 读取properties配置文件
- SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
- springboot 修改默认加载的配置文件不为application.properties