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
  • 相关阅读:
    常用的算法
    2017前端面试题
    深入了解php opcode缓存原理
    0=='aa'的结果是true
    关于PHP浮点数之 intval((0.1+0.7)*10) 为什么是7
    linux grep命令
    linux awk命令详解
    PHP socket模拟POST请求
    shell编程之sed
    Shell脚本常用判断
  • 原文地址:https://www.cnblogs.com/pu20065226/p/11758379.html
Copyright © 2011-2022 走看看