2.yml配置添加你自己的盐值com.github.ulisesbocchio jasypt-spring-boot-starter1.14 com.github.ulisesbocchio jasypt-spring-boot1.14
#jasypt加密的盐值
jasypt:
encryptor:
password: mykey
3.写测试类生成密码
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;
import org.junit.Test;
public class JasyptTest {
// 加密
@Test
public void testEncrypt() throws Exception {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES"); // 加密的算法,这个算法是默认的
config.setPassword("rfid"); // 加密的密钥
standardPBEStringEncryptor.setConfig(config);
String plainText = "root";
String encryptedText = standardPBEStringEncryptor.encrypt(plainText);
System.out.println("加密后的密码:"+encryptedText);
}
// 解密
// @Test
// public void testDe() throws Exception {
// StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
// EnvironmentPBEConfig config = new EnvironmentPBEConfig();
//
// config.setAlgorithm("PBEWithMD5AndDES");
// config.setPassword("D30CCEEC367C55F0E4C7B3BE8207C5DD");
// standardPBEStringEncryptor.setConfig(config);
// String encryptedText = "a2Dg/nGebGU7dlTTaI93x4KVA0UMd0IvdMIs1OYHZCU=";
// String plainText = standardPBEStringEncryptor.decrypt(encryptedText);
// System.out.println(plainText);
// }
}
示例 :LRXUUqO9Az60LdzTzfEPow==
4.放到你的数据库配置生成以后的密钥,注意要用 ENC() 包起来 如下ENC(LjaWI1eGcY02T1LLeZyLPg==)5.放到数据库的指定配置位置就行



