当前位置: 首页 > backend >正文

Spring Boot 使用 jasypt配置明文密码加密

  1. 引入依赖

    <dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>3.0.4</version>
    </dependency>
    
  2. 添加配置

    jasypt:encryptor:password: p@ssw0rd&Hubt2ec980e$ttsalgorithm: PBEWithMD5AndDES# 配置初始化向量生成器,解决Jasypt 3.0.3及以上版本启动报错的问题# NoIvGenerator表示不使用向量生成器(即无向量)iv-generator-classname: org.jasypt.iv.NoIvGenerator
    
  3. 生成密码的加密串

    import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;public class JasyptUtils {public static void main(String[] args) {//明文密码String password = "Mysql@123";//自定义密钥:与配置文件中的 jasypt.encryptor.password 保持一致String secretKey = "p@ssw0rd&Hubt2ec980e$tts";// 算法:与配置文件中的 jasypt.encryptor.algorithm 保持一致String algorithm = "PBEWithMD5AndDES";// 创建加密器对象StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();encryptor.setPassword(secretKey);encryptor.setAlgorithm(algorithm);// 执行加密操作System.out.println("加密前:" + password);String encryptedPassword = encryptor.encrypt(password);System.out.println("加密后:" + encryptedPassword);    }
    }
    
  4. 替换明文密码

    spring:#数据库datasource:driver-class-name:com.mysql.cj.jdbc.Driverur1: jdbc:mysql://127.0.0.1:3306/decoration_management_v1?useUnicode=true&characterEncoding=utf8username: root#password: Mysal@123password:ENC(nr029lISw82X2u3/eTHwUQ9W8C8gk04)#Redis configredis:host: 127.0.0.1#password: Rds&P@ssWOrd!password:ENC(Ew0ugG5tzly9x6Ihklp0flzqBjwGVpAb)uatapase.ssl:false
    

    配置方式:ENC(加密串)

http://www.xdnf.cn/news/7673.html

相关文章:

  • 第6章 C控制语句:循环
  • 攻防世界-题目名称-文件包含
  • MySQL 库的操作 -- 字符集和校验规则,库的增删查改,数据库的备份和还原
  • Java IO流操作
  • Prosys OPC:引领工业互联的OPC UA先锋
  • 游戏引擎学习第296天:层的雾效和透明度
  • 基于Spring Boot + Vue的教师工作量管理系统设计与实现
  • 监控易一体化运维:解锁工单管理效能,为运维工作提速
  • ZooKeeper 原理解析及优劣比较
  • 安达发|传统排产已过时?AI机器人+APS高级排产软件重塑制造业!
  • docker 查看镜像所在位置
  • Index-AniSora论文速读:探索Sora时代动画视频生成的前沿
  • Qt中解决Tcp粘包问题
  • Runtipi - 开源个人家庭服务器管理工具
  • C#调用GTS控制板
  • DeepSeek+PiscTrace+YOLO:迅速实现Mask掩码抠图
  • IEEE 802.1Q协议下封装的VLAN数据帧格式
  • 【ISP算法精粹】什么是global tone mapping和local tone mapping?
  • 异步复位,同步释放
  • FineBI 和 Axure工具比较——数据分析VS原型设计
  • 常见回归损失函数详解:L1 Loss, L2 Loss, Huber Loss
  • 能碳一体化的核心功能模块
  • 【图像大模型】Kolors:基于自监督学习的通用视觉色彩增强系统深度解析
  • 抓包分析工具与流量监控软件
  • C语言入门
  • SQLite基础及优化
  • 从0到1搭建shopee测评自养号系统:独立IP+硬件伪装+养号周期管理​
  • [概率论基本概念1]什么是经验分布
  • 【NLP 76、Faiss 向量数据库】
  • Easylogging使用笔记