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
  • 相关阅读:
    PXE无人自动安装系统 大风起
    httpd基于域名的虚拟主机的简单介绍 大风起
    tomcat优化方案 大风起
    tomcat架构 大风起
    Tomcat优化2 大风起
    NET 2.0学习
    删除VS2005历史记录
    在淘宝上建了个小店,在自己的小窝里宣传一下
    微软提供的ASP.NET 2.0空间,你还不赶紧去注册!!呵呵
    DataGridView.BackGroundImage你用过吗?
  • 原文地址:https://www.cnblogs.com/pu20065226/p/11758379.html
Copyright © 2011-2022 走看看