当前位置:首页 > 通信资讯 > 正文

引入maven 坐标

?
1 2 3 4 5 <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.4</version> </dependency>

配置密钥

?
1 2 #jasypt加密的盐值 jasypt.encryptor.password=jsuuwjnf

生成加密字符串

?
1 2 3 4 5 6 7 8 9 10 11 12 13 @Autowired StringEncryptor encryptor; @Test void test1() { String url = encryptor.encrypt("jdbc:mysql://192.168.134.135:3306/rbac?serverTimezone=UTC&useSSL=false&characterEncoding=utf8"); String name = encryptor.encrypt("root"); String password = encryptor.encrypt("12321573"); System.out.println(url); System.out.println(name); System.out.println(password); }

生成结果

springboot项目使用jasypt加密数据库密码(springboot jasypt解密)

修改原先的数据库连接信息

# 加密后的数据库url
spring.datasource.url=ENC(ztfgopw048yih3D45sPq4ia7v4rTDnvE+4Oye2rMyN9XBOovSlX5k3CHs1K4mBylbGGmf8blj1QPBqdSEA4UGIGLdQ1Qaj4+8kmUGrmAzXN6/Qh1CNxUpeZgghNe0HJ5NqPoGa+sSsPh9JIdhlrvhE6YYfAXTyxEpyUa5wTj0Tw=)
# 加密后的数据库用户名&&密码:
spring.datasource.username=ENC(68DX3O6HbDljx70ttga6wvtzaGnmswMNGCcq+QWtq8aih4xcTrcpDEeYHYLX+FYa)
spring.datasource.password=ENC(60cxL9lRBQAtWX+Yuk6Sb5NBwWN9juj2vCe/uUqudb9rwXClYOyO4eN4jOEVy6o5)

测试

使用加密后的数据源信息,正常连接数据库,测试请求通过。
此外,加密盐值在生成加密信息以后可以删掉,在部署spring boot项目的时候通过命令行的方式将盐值注入进去,防止数据源信息被解密。
java -jar app-0.0.1-SNAPSHOT.jar --jasypt.encryptor.password=xxxx

总结

本篇文档只是基于简单的加密角度来编写,未深入探讨,若有不足还请指正。

到此这篇关于springboot 项目使用jasypt加密数据源的文章就介绍到这了,更多相关jasypt加密数据源内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_41630045/article/details/121035207

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。