springboot接口请求和响应解密加密

这是一次巧合搜索到,但是也没有看懂是个啥样字。

因为所有贴出来的只有代码,没有效果图。

出于好奇,下载了代码

运行起来了。

但是没有效果

开始我是下载这里的

https://blog.csdn.net/hkk666123/article/details/114957024

指引的代码

 https://gitlab.com/tpc.edu/encrypt/encrypt-body-demo

一度怀疑。

第二天又来看是什么原因。

找到这个

https://gitee.com/licoy/encrypt-body-spring-boot-starter

根据他的指示替换了加密类

运行Application 类

也替换了

import cn.licoy.encryptbody.annotation.EnableEncryptBody;
控制器也替换了
import cn.licoy.encryptbody.annotation.EnableEncryptBody;
import org.springframework.boot.SpringApplication;

终于看到了效果

新建的运行类

Application
package edu.tpc.encryptbody;

import cn.licoy.encryptbody.annotation.EnableEncryptBody;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@EnableEncryptBody
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

新建的控制器

TestController 
package edu.tpc.encryptbody.controller;


import cn.licoy.encryptbody.annotation.encrypt.EncryptBody;
import cn.licoy.encryptbody.enums.EncryptBodyMethod;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/test")
public class TestController {

    @GetMapping
    @ResponseBody
    @EncryptBody(value = EncryptBodyMethod.AES)
    public String test(){
        return "hello world";
    }


}

效果图

到此demo效果已经运行出来了。

也使我想到了小鹅通 。

他们保护资源的功能推测也是使用了此技术。

通过此次发现。也让我感慨,原来保护资源本不只有类似微信支付签名那么一种方法。

是多种多样的。

需要好奇心,需要探索!

其他参考文章和链接:

https://blog.csdn.net/xxssyyyyssxx/article/details/88219298

https://github.com/brix/crypto-js

https://github.com/ishuibo/rsa-encrypt-body-spring-boot

原文地址:https://www.cnblogs.com/xiaohuasan/p/14917599.html