一、修改pom文件
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
二、在启动类中加上注解 @EnableEncryptableProperties
3、在CryptoUtil中工具类中生成加密数据
package com.wengegroup.dqgzSystem.utils;//package com.zyc.commons.utils.utils;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
/**
* @author fubc
* @date 2022/10/12 12:06
* @Deception jasypt加密解密工具类
*/
public class CryptoUtil {
//ZYC-SERVICE-2023
private static String password="02700083-9fd9-4b82-a4b4-9177e0560e92" ;
/**
* 原始值加密
*
* @param sourceValue 原始值
* @return lang.String
*/
public static String encrypt(String sourceValue) {
StandardPBEStringEncryptor textEncryptor = new StandardPBEStringEncryptor();
textEncryptor.setPassword(password);
return textEncryptor.encrypt(sourceValue);
}
/**
* 加密值解密
*
* @param encryptValue 加密结果值
* @return lang.String
*/
public static String decrypt(String encryptValue) {
StandardPBEStringEncryptor textEncryptor = new StandardPBEStringEncryptor();
textEncryptor.setPassword(password);
return textEncryptor.decrypt(encryptValue);
}
public static void main(String[] args) {
System.out.println(encrypt("sprint01"));
System.out.println(encrypt("Sprint02@mysql"));
System.out.println(encrypt("elastic"));
System.out.println(encrypt("eTB31k3xozXS6CsGtkSa"));
}
}
CryptoUtil.java
4、在yml文件中添加
jasypt:
encryptor:
password: 02700083-9fd9-4b82-a4b4-9177e0560e92
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
5、把CryptoUtil中生成的加密的用户名和密码放入配置文件中
username: ENC(B7or6y0UK+QwsKlJYmRbUA==)
password: ENC(Km0L2gDrFTPtJ+VTDZN2fXYv19UZ+OAM0am5+ACv8Wg=)