• springboot 配置文件密码加密处理


    一、修改pom文件

    com.github.ulisesbocchio

    jasypt-spring-boot-starter

    3.0.4

    二、在启动类中加上注解 @EnableEncryptableProperties

     

     

    3、在CryptoUtil中工具类中生成加密数据

    1. package com.wengegroup.dqgzSystem.utils;//package com.zyc.commons.utils.utils;
    2. import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
    3. /**
    4. * @author fubc
    5. * @date 2022/10/12 12:06
    6. * @Deception jasypt加密解密工具类
    7. */
    8. public class CryptoUtil {
    9. //ZYC-SERVICE-2023
    10. private static String password="02700083-9fd9-4b82-a4b4-9177e0560e92" ;
    11. /**
    12. * 原始值加密
    13. *
    14. * @param sourceValue 原始值
    15. * @return lang.String
    16. */
    17. public static String encrypt(String sourceValue) {
    18. StandardPBEStringEncryptor textEncryptor = new StandardPBEStringEncryptor();
    19. textEncryptor.setPassword(password);
    20. return textEncryptor.encrypt(sourceValue);
    21. }
    22. /**
    23. * 加密值解密
    24. *
    25. * @param encryptValue 加密结果值
    26. * @return lang.String
    27. */
    28. public static String decrypt(String encryptValue) {
    29. StandardPBEStringEncryptor textEncryptor = new StandardPBEStringEncryptor();
    30. textEncryptor.setPassword(password);
    31. return textEncryptor.decrypt(encryptValue);
    32. }
    33. public static void main(String[] args) {
    34. System.out.println(encrypt("sprint01"));
    35. System.out.println(encrypt("Sprint02@mysql"));
    36. System.out.println(encrypt("elastic"));
    37. System.out.println(encrypt("eTB31k3xozXS6CsGtkSa"));
    38. }
    39. }

    CryptoUtil.java

    4、在yml文件中添加

    jasypt:

    encryptor:

    password: 02700083-9fd9-4b82-a4b4-9177e0560e92

    algorithm: PBEWithMD5AndDES

    iv-generator-classname: org.jasypt.iv.NoIvGenerator

    5、把CryptoUtil中生成的加密的用户名和密码放入配置文件中

    username: ENC(B7or6y0UK+QwsKlJYmRbUA==)

    password: ENC(Km0L2gDrFTPtJ+VTDZN2fXYv19UZ+OAM0am5+ACv8Wg=)

    6、正常启动即可

  • 相关阅读:
    arcgis中xy连线时出现多余的线
    CSP-J-2016-海港
    CAN透传云网关给EPEC3724控制器升级方案
    栈,单调栈,队列,单调队列
    Docker 第十三章 : Docker 三剑客之 Swarm(服务管理命令)
    C++系列--this指针的用途
    关于测试的思考-质量保障体系
    ubuntu22.04为什么鼠标会自动丢失焦点
    Methodology for augmented reality-based adaptive assistance in industry
    C语言数组
  • 原文地址:https://blog.csdn.net/libaowen609/article/details/131081645