Spring Boot 3.x 中使用 Jasypt 时加解密不生效

遇到一个问题, 在Spring Boot 3.x 中使用 Jasypt 时,无法正常解密数据库密码,导致项目无法启动。提示如下

复制代码
***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.datasource.dynamic.datasource.smart-manager.password' to java.lang.String:

    Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.dynamic.datasource.smart-manager.password' to java.lang.String

Action:

Update your application's configuration

经排查发现,该问题与 Spring Boot 3.x 的版本兼容性有关。Jasypt 3.x 默认采用强加密算法 PBEWITHHMACSHA512ANDAES_256。而当前使用的是旧算法 PBEWithMD5AndDES,因此需要额外添加配置,为其指定对应的 IV 生成器。

所以除了其他配置配置正确之外,配置文件需要这样写

复制代码
jasypt:
  encryptor:
    # 指定加密盐值,生产环境建议通过环境变量或启动参数传入,切勿硬编码
    password: ****************
    # 关键:指定使用旧算法
    algorithm: PBEWithMD5AndDES
    # 关键:为旧算法指定对应的IV生成器
    iv-generator-classname: org.jasypt.iv.NoIvGenerator
相关推荐
用户31268748772019 小时前
AI Agent 开发实战(六):用 Spring AI 搭建你的第一个 Agent
spring boot·openai
zhangjw3420 小时前
第36篇:Spring Boot进阶:Web开发+参数校验+全局异常处理
前端·spring boot·后端
完美火龙篇 四月的友20 小时前
SpringBoot 即时聊天 IM 完整实现(HTTP会话管理 \+ WebSocket实时推送 \+ 离线消息)
spring boot·websocket·http
Bug收容所21 小时前
12305项目学习day5
java·spring boot·redis·mysql·spring·rocketmq
小Ti客栈1 天前
Spring Boot 集成 Springdoc-OpenAPI 与 Knife4j实现接口文档与可视化调试
java·spring boot·后端
paopaokaka_luck2 天前
基于Springboot3+Vue3的高校选课系统(AI选课助手、协同过滤算法、分享到微博、扣扣、Echarts图形化分析)
网络·spring boot·网络协议·echarts
小Ti客栈2 天前
Spring Boot 整合 Swagger2 和 Knife4j实现接口文档与可视化调试
java·spring boot·后端
2601_963870172 天前
【计算机毕业设计】基于Spring Boot的社区老年大学课程报名与学习系统的设计与实现
java·spring boot·学习
weixin_BYSJ19872 天前
springboot3家政平台小程序--附源码00904
java·javascript·spring boot·python·django·flask·php