Springboot项目对数据库用户名密码实现加密过程解析
作者:丶sky丶fx 时间:2024-01-19 23:02:04
pom.xml文件中引入如下内容
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.16</version>
</dependency>
保存pom.xml文件,更新jar
将当前路径切换到jasypt包目录下:
使用如下命令进行密码加密:
java -cp jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="password" password=fantasy algorithm=PBEWithMD5AndDES
其中input为需要加密的密码
password为加密时采用的秘钥
algorithm为加密算法,默认算法为PBEWithMD5AndDES
最后得到password加密后的密文:2p9NblOkkwNqsYhDruu5TFPR1RgkL9aH
注意:每次运行得到的结果不一样(不用好奇,都是有效的)
将加密后密码密文配置到spring boot的配置文件的数据源配置选项中
如:spring.datasource.password=ENC(2p9NblOkkwNqsYhDruu5TFPR1RgkL9aH)
在程序中获取到的spring.datasource.password会自动转换成明文内容(password)
注意:密文格式为
ENC(密文)
在java启动的环境变量中设置加密的秘钥
-Djasypt.encryptor.password=fantasy
5.启动项目,正常访问就OK了!
来源:https://www.cnblogs.com/sky-fx/p/13099847.html
标签:Spring,boot,数据,库,加密
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
django自定义模板标签过程解析
2023-07-29 12:34:57
![](https://img.aspxhome.com/file/2023/3/70713_0s.png)
剖析Python的Tornado框架中session支持的实现代码
2022-12-06 17:53:13
js传值后台中文出现乱码的解决方法
2024-02-25 11:52:23
用户体验 保守的使用下拉菜单
2008-01-15 20:00:00
sql2005 日志清理 SQL2005压缩清除日志的方法
2024-01-28 12:59:25
layui表单提交到后台自动封装到实体类的方法
2024-04-22 22:33:11
![](https://img.aspxhome.com/file/2023/8/135648_0s.jpg)
Python跨文件全局变量的实现方法示例
2021-05-26 08:13:23
python画立方体--魔方
2022-04-22 10:20:43
![](https://img.aspxhome.com/file/2023/8/117468_0s.png)
Django中Migrate和Makemigrations实操详解
2021-09-12 02:34:23
![](https://img.aspxhome.com/file/2023/6/134726_0s.png)
ASP教程:自己写的数据库操作类
2008-11-21 17:29:00
一文带你搞懂JS中导入模块import和require的区别
2023-07-21 03:24:18
PHP概率计算函数汇总
2023-11-19 08:06:19
FusionCharts图表显示双Y轴双(多)曲线
2023-08-22 17:55:38
![](https://img.aspxhome.com/file/2023/9/56199_0s.png)
Python使用os模块实现更高效地读写文件
2021-08-11 00:41:39
![](https://img.aspxhome.com/file/2023/3/117923_0s.png)
ie7.0浏览器 兼容问题苦煞网站设计者
2007-08-08 17:11:00
python list格式数据excel导出方法
2023-09-19 14:21:01
在matplotlib的图中设置中文标签的方法
2023-10-10 07:17:53
![](https://img.aspxhome.com/file/2023/3/65873_0s.jpg)
详解Python中的内建函数,可迭代对象,迭代器
2023-08-23 13:48:07
![](https://img.aspxhome.com/file/2023/9/128559_0s.jpg)
盲人站长深恶痛绝的onfocus=”this.blur()”
2011-04-22 12:25:00
Python实现信息管理系统
2022-10-08 22:28:39
![](https://img.aspxhome.com/file/2023/9/80419_0s.jpg)