Skip to content

🔒 SpringBoot控制器统一的响应体编码/加密与请求体解密的注解处理方式,支持MD5/SHA/AES/DES/RSA | SpringBoot controller unified response body encoding/encryption and request body decryption annotation processing method.

License

Notifications You must be signed in to change notification settings

Licoy/encrypt-body-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

简体中文 | English

介绍

encrypt-body-spring-boot-starter是对springboot控制器统一的响应体编码/加密与请求体解密的注解处理方式,支持MD5/SHA/AES/DES/RSA。

编码/加密解密支持

  • 可进行编码/加密的方式有:
      • MD5
      • SHA-1 / SHA-256
      • AES
      • DES
      • RSA
  • 可进行解密的方式有:
      • AES
      • DES
      • RSA

引入注册

导入依赖

在项目的pom.xml中引入依赖:

<dependency>
    <groupId>cn.licoy</groupId>
    <artifactId>encrypt-body-spring-boot-starter</artifactId>
    <version>1.2.3</version>
</dependency>

启用组件

  • 在工程对应的Application类中增加@EnableEncryptBody注解,如:
@EnableEncryptBody
@SpringBootApplication
public class Application {
    
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

配置参数

在项目的application.ymlapplication.properties文件中增加参数配置,例如:

encrypt:  
    body:
      aes-key: 12345678 #AES加密秘钥
      des-key: 12345678 #DES加密秘钥
      # more...

使用

对整个控制器生效

@RestController
@EncryptBody
@RequestMapping("/test")
public class TestController {

    @GetMapping
    public String test(){
        return "hello world";
    }

}

对单一请求生效

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

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

}

对响应的声明类生效

@Data
@EncryptBody
public class User implements Serializable {

    private String name;

    private String email;

    private Integer number;

    private String numberValue;

}

对声明类单一属性生效

@Data
@EncryptBody
@FieldBody
public class User implements Serializable {

    private String name;

    @FieldBody
    @AESEncryptBody(key = "1234567812345678")
    private String email;

    @FieldBody(field = "numberValue", clearValue = true)
    @DESEncryptBody(key = "1234567812345678")
    private Integer number;

    private String numberValue;

}

注解一览表

开源协议

Apache 2.0

About

🔒 SpringBoot控制器统一的响应体编码/加密与请求体解密的注解处理方式,支持MD5/SHA/AES/DES/RSA | SpringBoot controller unified response body encoding/encryption and request body decryption annotation processing method.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages