Spring Boot 配置 - 配置信息加密
2019-10-31 21:40
363 查看
▶ Spring Boot 依赖与配置
Maven 依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency>
▶ 使用说明
假设有配置项
com.anoyi.custom.name=anoyi不能明文显示,则可以使用
jasypt的
PBEWithMD5AndDES算法加密算法进行如下配置:
com.anoyi.custom.name=ENC(TqrnYZn55aFVwnSo2TrbFA==) jasypt.encryptor.password=anoyi
jasypt.encryptor.password
为自定义值,用此密码加密的明文,需要用此密码解密密文ENC(...)
为jasypt
提供的加密标识,Spring Boot 服务启动时,加载各种 properties 时会依据此标识判断是否解密赋值,可自定义TqrnYZn55aFVwnSo2TrbFA==
为明文字符串anoyi
通过密码anoyi
加密后得到的值,此值不唯一,即同一明文通过同一密码加密会得到不同的值
▶ 配置说明
基于 Password 的加密配置
参数 | 必填 | 默认值 |
---|---|---|
jasypt.encryptor.password | True | - |
jasypt.encryptor.algorithm | False | PBEWithMD5AndDES |
jasypt.encryptor.keyObtentionIterations | False | 1000 |
jasypt.encryptor.poolSize | False | 1 |
jasypt.encryptor.providerName | False | SunJCE |
jasypt.encryptor.providerClassName | False | null |
jasypt.encryptor.saltGeneratorClassname | False | org.jasypt.salt.RandomSaltGenerator |
jasypt.encryptor.ivGeneratorClassname | False | org.jasypt.salt.NoOpIVGenerator |
jasypt.encryptor.stringOutputType | False | base64 |
jasypt.encryptor.proxyPropertySources | False | false |
最新版的
jasypt还支持非对称加密、自定义加密器等等功能,更多信息:
MORE :https://github.com/ulisesbocchio/jasypt-spring-boot
▶ 配置参数加解密
添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency>
示例加解密字符串 anoyi
@RunWith(SpringRunner.class) @SpringBootTest public class EncryptTest { @Autowired private StringEncryptor jasyptStringEncryptor; @Test public void encrypt() { String encryptStr = jasyptStringEncryptor.encrypt("anoyi"); System.out.println(encryptStr); } @Test public void decrypt() { String encryptStr = jasyptStringEncryptor.decrypt("TqrnYZn55aFVwnSo2TrbFA=="); System.out.println(encryptStr); } }
▶ Github Demo URL
- https://github.com/ChinaSilence/spring-boot-demos/tree/master/05%20-%20config%20encrypt
© 著作权归作者所有,转载或内容合作请联系作者
● 史上最轻松入门之Spring Batch - 轻量级批处理框架实践
● APM工具寻找了一圈,发现SkyWalking才是我的真爱
● Spring Boot 注入外部配置到应用内部的静态变量
● Java 使用 UnixSocket 调用 Docker API
● Service Mesh - gRPC 本地联调远程服务
本文由博客一文多发平台 OpenWrite 发布!
相关文章推荐
- Jasypt : 整合spring boot加密应用配置文件敏感信息
- Spring Boot: 加密应用配置文件敏感信息
- Spring Boot: 加密应用配置文件敏感信息
- Logback配置文件使用Springboot配置信息
- Spring+Hibernate 数据库配置信息的加密
- spring boot 配置文件密码加密支持
- Prometheus 和micrometer 与Spring boot 配置信息
- Spring-Boot数据库密码加密配置
- 利用Jasypt如何对Spring Boot配置文件加密
- Spring boot pom.xml和application.properties配置信息
- SpringBoot中配置文件优先级和有哪些方式获取配置文件中的信息
- springboot项目使用@Value注解获取配置文件中的配置信息
- 项目学子商城(加密,异常,拦截器SpringBoot没有xml配置文件,附常见配置错误)
- Spring Boot下集成Jasypt对配置文件进行加密
- spring-boot properties 配置信息
- 11-Spring Boot ( 获取配置文件信息 )
- spring 配置中,数据库相关信息如何加密放在属性文件中
- SpringBoot中加密包对配置文件中的密码进行加密
- spring+jpa配置加密的数据库信息
- 关于springboot配置文件数据源加密的问题