SpringBoot项目数据库明文加密
1.添加依赖 <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot</artifactId> <version>1.18</version> </dependency> 2.明文加密 public class EncryUtil { public static void main(String[] args) { StandardPBEStringEncryptor standardPBEStringEncryptor= new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm("PBEWithMD5AndDES"); // 秘钥 config.setPassword("12345"); standardPBEStringEncryptor.setConfig(config); String text="xxx"; // 4/uN4vXGnsNvITrC04cJ9Q== String encryStr = standardPBEStringEncryptor.encrypt(text); System.out.println(encryStr); String text1="xxx"; // 8B/C8+1dfxEnmcz4uH+UsA== String encryStr1 = standardPBEStringEncryptor.encrypt(text1); System.out.println(encryStr1); } } 3.更新配置文件 将加密后的密文用 ENC(密文) 进行替换 添加加密的配置 jasypt: encryptor: password: 12345 algorithm: PBEWithMD5AndDES 4.开启服务解密注解 @EnableEncryptableProperties
凡所有相,皆是虚妄