使用jasypt对springboot的datasource密码加密

本文介绍如何使用 Jasypt 在 Spring Boot 中加密数据库连接密码。通过在 pom.xml 文件中引入依赖并使用命令行工具生成加密密文,可以将数据库密码安全地存储在配置文件中。

1.pom.xml 文件中引入

 

[plain] view plain copy

  1. <!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter -->  
  2. <!-- 整合jasypt对数据库密码加密 -->  
  3. <dependency>  
  4.     <groupId>com.github.ulisesbocchio</groupId>  
  5.     <artifactId>jasypt-spring-boot-starter</artifactId>  
  6.     <version>1.16</version>  
  7. </dependency>  

 

2.在windows下命令生成加密密文

 

[plain] view plain copy

  1. java -cp G:\maven\repository\org\jasypt\jasypt\1.9.2\jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="you4new!" password=saltnewfor algorithm=PBEWithMD5AndDES  


参数说明:

 

input =数据库链接密码

 

password=加密字段,随意设置

algorithm= 算法

执行后有以下输出

 

[plain] view plain copy

  1. ----ENVIRONMENT-----------------  
  2.   
  3. Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.131-b11  
  4.   
  5.   
  6.   
  7. ----ARGUMENTS-------------------  
  8.   
  9. algorithm: PBEWithMD5AndDES  
  10. input: you4new!  
  11. password: saltnewfor  
  12.   
  13.   
  14.   
  15. ----OUTPUT----------------------  
  16.   
  17. UK61bS+W/BskHl0N0ViAQcrPAmZLZZwO  

3.在spring boot 项目的配置文件中加入以下内容

 

[plain] view plain copy

  1. #spring.datasource.url=jdbc:mysql://localhost:3306/Solrsearch  
  2. #spring.datasource.username=root  
  3. #jasypt.encryptor.password=${password}  
  4. #jasypt.encryptor.password=aidan123456  
  5. #spring.datasource.password=ENC(UK61bS+W/BskHl0N0ViAQcrPAmZLZZwO)  
  6. #spring.datasource.driver-class-name=com.mysql.jdbc.Driver  

 

[plain] view plain copy

  1.   

 

https://www.ricston.com/blog/encrypting-properties-in-spring-boot-with-jasypt-spring-boot/

https://www.ricston.com/blog/encrypting-properties-in-spring-boot-with-jasypt-spring-boot/

http://www.cnblogs.com/zz0412/p/jasypt-001.html

https://github.com/ulisesbocchio/jasypt-spring-boot

转载于:https://my.oschina.net/xiaominmin/blog/1795627

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值