首页 > 数据库技术 > 详细

springboot项目配置文件中的数据库用密文展示如何做

时间:2020-08-14 01:56:29      阅读:97      评论:0      收藏:0      [点我收藏+]

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)

技术分享图片

 

 

springboot项目配置文件中的数据库用密文展示如何做

原文:https://www.cnblogs.com/zhangshitong/p/13498445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!