zoukankan      html  css  js  c++  java
  • spring boot密码管理

    1.引入依赖

            <dependency>
                <groupId>com.github.ulisesbocchio</groupId>
                <artifactId>jasypt-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>

    配置文件中

    db.password=ENC(XvP2P4H3cLzf8r/ak91xLg==)

    2.controller中

    package com.example.configcenter;
    
    
    import org.jasypt.intf.service.JasyptStatelessService;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import javax.annotation.Resource;
    
    
    @RequestMapping("/ConfigClientDemo")
    @RestController
    public class ConfigClientDemoController {
        @Value("${db.password}")
        private String testName;
    

    @PostMapping("/getServiceMethod") public String echo(String name){ return "wahaha"+name; } @PostMapping("/encrypt") public String encrypt(String input,String encodeKey){ JasyptStatelessService service = new JasyptStatelessService(); String result = service.encrypt(input, encodeKey, (String)null, (String)null, "PBEWithMD5AndDES", (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null); return result ; } }

    3.启动参数中加入密钥

    -Djasypt.encryptor.password=pwd

    4.调用

    http://localhost:8705/ConfigClientDemo/encrypt?input=123456&encodeKey=pwd

    返回:XvP2P4H3cLzf8r/ak91xLg==

    将此 放入配置文件中

    重启项目

    访问方法

    "wahaha"+str
  • 相关阅读:
    20190425 发现了一家不错的咖啡店---半生咖啡
    20190425 这个。。。
    20190425 看数据统计和数据挖掘让我写了一篇杂文
    20190424 数据仓库 维度建模(一)
    20190423 PowerDesigner 数据库模型快速建立
    Xshell安装后,使用的优化
    Linux系统安装和网络配置
    Linux发展史-简简简易版
    服务器硬件
    git 常用命令
  • 原文地址:https://www.cnblogs.com/pu20065226/p/11758379.html
Copyright © 2011-2022 走看看