简单粗暴,直接上代码
- 引入依赖包
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.16</version>
</dependency>
- 生成加密后的密码
C:\Users\admin>java -cp C:\Users\admin\.m2\repository\org\jasypt\jasypt\1.9.2\jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="123456" password=1ab1cd2ef4hd algorithm=PBEWithMD5AndDES
----ENVIRONMENT-----------------
Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.121-b13
----ARGUMENTS-------------------
algorithm: PBEWithMD5AndDES
input: 123456
password: 1ab1cd2ef4hd
----OUTPUT----------------------
yEV66fWm/1goY0/y8VRhNg==
algorithm:加密方式
input:明文密码
password:盐值
OUTPUT:加密后的密码
3. 配置文件
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@127.0.0.1:1521/test
username: test
password: ENC(yEV66fWm/1goY0/y8VRhNg==) #ENC(密文)
jasypt:
encryptor:
password: 1ab1cd2ef4hd #盐值