【加密解密】加密解密 明文加密解密 用户名加密解密

使用:Jasypt加密库对配置文件中明文密码加密:

1、加载jasypt包。
gradle配置:

implementation group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '3.0.4'

或者:pom.xml文件:

<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>

2、jasypt配置、数据库配置:
application.properties文件:

#123wes为自定义加密盐:(jasypt配置一定要放最上面)
jasypt.encryptor.password=123wes
#加密方式 (切勿修改,若修改:同加密方法一并修改。)
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator
jasypt.encryptor.algorithm=PBEWithMD5AndDES

#数据连接配置:
spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/databasesName?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
spring.datasource.username= ENC(Bf1Y3jZLLuLnkX1T2kXu9/r/Pil//fM6)
spring.datasource.password= ENC(dfCDWWWEEgs4YXDDFKKK9kGW)
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver


或者:yml文件:

jasypt:
encryptor:
password:123wes
iv-generator-classname:org.jasypt.iv.NoIvGenerator
algorithm:PBEWithMD5AndDES

#数据库配置:
spring:
datasource:
jdbc-url:mysql://localhost:3306/databasesName?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
username: ENC(Bf1Y3jZLLuLnkX1T2kXu9/r/Pil//fM6)
password: ENC(dfCDWWWEEgs4YXDDFKKK9kGW)
driver-class-name:com.mysql.cj.jdbc.Driver

3、至此;点击Run运行项目。可正常运行。

4、加密解密方法:(即:ENC()括号中密文的获取)

请看原文:https://blog.csdn.net/xysxlgq

若报错:

Failed to bind properties under 'spring.datasource.password' to java.lang.String:

Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String

Action:

Update your application's configuration

解决方法:

 

posted @ 2022-08-03 22:23  刘贵庆  阅读(600)  评论(0编辑  收藏  举报