网站首页 > 博客文章 正文
前言
由于系统安全的考虑,配置文件中不能出现明文密码的问题,本文就给大家详细介绍下springboot配置数据库密码加密的方法,下面话不多说了,来一起看看详细的介绍吧
1.导入依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
2.找到jasypt-1.9.2.jar所在位置,打开cmd
3.输入如下命令执行
java -cp jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="123456" password=sad124f1f1rf1fgt5 algorithm=PBEWithMD5AndDES
input :明文密码
password:要加的盐(可自己设置)
algorithm:加密算法,这里使用 PBEWithMD5AndDES
结果如下,OUTPUT就是加密之后的密文(密码)
4.在application.yml文件中配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: ENC(HPPHfpHVXzNf00SQLBrjug==)
password: ENC(F8ckXFGTF6Wu8dQ51hoNBw==)
url: jdbc:mysql://localhost:3306/foodie-shop-dev?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
jasypt:
encryptor:
password: sad124f1f1rf1fgt5
5.在启动类Application.java中配置注解,配置完成
//配置数据库加密注解
@EnableEncryptableProperties
6.小结
除了加密MySQL密码的例子之外,当配置文件中有多个密码、Token等需要加密时,这个方法就比较方便了。
除了支持字符串秘钥,jasypt还支持key文件秘钥,更加安全。
在安全要求很高时,还可以使用jasypt默认PBEWITHHMACSHA512ANDAES_256加密算法,该算法需要安装JCE支持。
7.问题
问题描述:在Spring Boot中使用jasypt-spring-boot进行加密,但是提示:
Description:
Failed to bind properties under 'spring.datasource.password' to java.lang.String:
Reason: Failed to bind properties under 'spring.datasource.password' to java.lang.String
Action:
Update your application's configuration
解决办法:
3.0.2更改了默认的加密算法,最后的办法是把版本降到2.1.2
总结
到此这篇关于springboot数据库密码加密配置的文章就介绍到这了,希望大家以后多多支持!
猜你喜欢
- 2024-11-13 spring boot配置文件敏感字段加密
- 2024-11-13 Spring Boot安全之application配置信息加密
- 2024-11-13 如何在SpringBoot项目中实现加密?
- 2024-11-13 SpringBoot进阶-SpringBoot如何实现配置文件脱敏?
- 2024-11-13 加密SpringBoot配置文件技巧(加密pdf文件如何解密编辑)
- 2024-11-13 Spring Boot版本和Jasypt版本的兼容性问题?
- 2024-11-13 SpringBoot加密配置属性(springboot配置密码加密)
- 2024-11-13 SpringCloud-OAuth2(二):实战篇(oauth2.0 springcloud)
- 2024-11-13 SpringBoot 配置文件这样加密,才足够安全!
- 2024-11-13 如何保护 SpringBoot 配置文件中的敏感信息
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)