Jasypt加解密 - 常见问题
Spring Boot Jasypt配置加密解密
怎么在 Spring Boot 中使用 Jasypt?
1. 依赖:
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.5</version> </dependency>
2. application.yml 配置密钥:
jasypt:
encryptor:
password: ${JASYPT_PASSWORD:your-secret-key}
algorithm: PBEWITHHMACSHA512ANDAES_256
3. 使用:
spring:
datasource:
password: ENC(加密后的密文)
密钥怎么安全保存?
不要把密钥提交到 Git!推荐用环境变量 export JASYPT_PASSWORD=xxx 或启动参数 --jasypt.encryptor.password=xxx。
支持哪些算法?
推荐新版 PBEWITHHMACSHA512ANDAES_256(本工具默认),兼容老版本 PBEWithMD5AndDES 等。