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)

  • 相关阅读:
    2011年10月小记
    修改模拟器hosts文件
    2011年9月小记
    解决IIS7.5站点不能登录SQLEXPRESS
    EF 4.3 CodeBased Migrations
    2012年5月 小记
    Android对SD卡进行读写
    Tomcat for Eclipse
    ARR2.5 配置反向代理
    作业2浅谈数组求和java实验
  • 原文地址:https://www.cnblogs.com/zhangshitong/p/13498445.html
Copyright © 2011-2022 走看看