您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

bubuko 2022/1/25 19:29:58 java 字数 3245 阅读 894 来源 http://www.bubuko.com/infolist-5-1.html

1.添加依赖: <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>1.16</version> </depende ...

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


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶