Awesome Open Source
Awesome Open Source

简体中文 | English

介绍

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

编码/加密解密支持

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

引入注册

导入依赖

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

<dependency>
    <groupId>cn.licoy</groupId>
    <artifactId>encrypt-body-spring-boot-starter</artifactId>
    <version>1.2.0</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



Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Java (385,554
Spring (28,754
Spring Boot (15,402
Encrypt (11,842
Des (6,871
English (6,855
Aes (3,424
Sha (3,337
Rsa (3,186
Decrypt (2,716
Spring Mvc (2,676
Spring Security (1,721
Md5 (1,394
Sha256 (831
Sha1 (722
Des Encryption (13