zoukankan      html  css  js  c++  java
  • springboot项目配置文件中的数据库用密文展示如何做

    1.添加依赖:

    <dependency>  
          <groupId>com.github.ulisesbocchio</groupId> 
          <artifactId>jasypt-spring-boot-starter</artifactId>
          <version>1.16</version>
     </dependency>
    2.在配置文件中设置加密的盐:
    jasypt.encryptor.password: test1234
    3.使用工具类:
    import org.jasypt.util.text.BasicTextEncryptor;
    
    /**
     * 处理加密/解密数据的工具
     *
     * @author zwq
     */
    public class JasyptEncryptUtil {
        public static  void  main(String[] args){
            BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
            //加密所需的salt(盐),注意要与 配置文件中设置jasypt.encryptor.password相同
            String salt = "test1234";
            //需要加密的数据
            String data = "password";
            textEncryptor.setPassword(salt);
            //加密数据
            String value = textEncryptor.encrypt(data);
            //加密的结果直接放入 application.yml中,注意加密后的数据要用按照 ENC(valaue) 的样式
            System.out.println("加密结果:"+value);
            //解密数据
            //String value = textEncryptor.decrypt("");
        }
    
    }

    4.修改配置文件中的数据:将第3步中打印的数据,写在配置文件中:

    password: ENC(05RybgJrpb+uEZ0tWWIfgyiS9nOMcnJm)

  • 相关阅读:
    查看当前系统的shell
    xargs命令,作用雷同|
    shell 行末尾的&含义
    apt-get 安装及卸载,dpkg查询安装文件
    Linux: mv and cp 拷贝不包含目录
    windows下远程连接ubunut
    Linux 清空屏幕
    PageHelper的一些属性设置
    HttpServletRequest
    铁电RAM为何比串行SRAM更好
  • 原文地址:https://www.cnblogs.com/zhangshitong/p/13498445.html
Copyright © 2011-2022 走看看