• springboot配置文件数据库账号密码加密


    配置文件配置暴露一些密码问题处理:

    jasypt 是一个简单易用的加解密Java库

    相关可以参考的国外大神写的源码的github地址

    github:https://github.com/ulisesbocchio/jasypt-spring-boot

    https://github.com/gxing19/Spring-Boot-Example/tree/master/spring-boot-password-encrypt

    以下是修改步骤(我用的是springboot框架):

    1、添加依赖:在pom.xml添加如下依赖

    <!-- jasypt加密 -->
    <dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>2.1.0</version>
    </dependency>

    2、配置文件设置 jasypt 密钥如:

    jasypt.encryptor.password=vh^onsYFUx^DMCKK

    3、编写测试代码生成密文
    package com.aisino.cma;

    import org.jasypt.encryption.StringEncryptor;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    /**
    * <p>
    * 前端控制器
    * </p>
    *
    * @author ranqw
    * @since 2020-06-03
    */

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class ApplicationProperties {

    @Autowired
    StringEncryptor encryptor;

    @Test
    public void jacketEncrypt() {

    //加密
    /*String name = encryptor.encrypt("XXX");
    String password = encryptor.encrypt("XXX");
    System.out.println("name 密文: " + name);
    System.out.println("password 密文: " + password);*/

    //解密
    /*String decrypt1 = encryptor.decrypt(name);
    String decrypt2 = encryptor.decrypt(password);
    System.out.println(decrypt1 + "------------" + decrypt2);*/
    }
    }

    4、spring.datasource.username 及 spring.datasource.password 配置生成的账密
    重启应用,查看数据库是否连接成功

     

  • 相关阅读:
    畅通工程(hdu1232)并查集
    qsort函数的用法
    二叉搜索树(hdu3791)
    Binary Tree Traversals(HDU1710)二叉树的简单应用
    Safe Or Unsafe(hdu2527)哈弗曼VS优先队列
    山东省第四届acm解题报告(部分)
    Points on Cycle (hdu1700,几何)
    A计划 hdu2102(bfs一般题)
    杀人游戏(hdu2211)插入法
    hdu1518 Square(dfs)
  • 原文地址:https://www.cnblogs.com/small-panda/p/13037588.html
Copyright © 2020-2023  润新知