1.application.yml配置
2.利用jaspty工具类将数据库密码明文加密
/**
* 明文加密
*/
public static String encrypt(String str,String pwd) {
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
basicTextEncryptor.setPassword(pwd);
String ciphertext = basicTextEncryptor.encrypt(str);
return ciphertext;
}
/**
* 解密
*/
public static String decrypt(String ciphertext,String pwd) {
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
basicTextEncryptor.setPassword(pwd);
ciphertext = "ENC(" + ciphertext + ")";
if (PropertyValueEncryptionUtils.isEncryptedValue(ciphertext)) {
String plaintext = PropertyValueEncryptionUtils.
decrypt(ciphertext, basicTextEncryptor);
return plaintext;
}
return "";
}
public static void main(String[] args) {
String str = encrypt("xjmfc1","123456");
System.out.println(str);
}
3.配置数据库密码