首页 > 编程语言 > 详细

spring boot密码管理

时间:2019-10-29 14:48:07      阅读:66      评论:0      收藏:0      [点我收藏+]

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

spring boot密码管理

原文:https://www.cnblogs.com/pu20065226/p/11758379.html

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