Skip to content

Latest commit

 

History

History
123 lines (106 loc) · 3.09 KB

README_EN.md

File metadata and controls

123 lines (106 loc) · 3.09 KB

简体中文 | English

Introduce

encrypt-body-spring-boot-starter is a unified annotation processing method for response body encoding/encryption and request body decryption for springboot controller, and supports MD5/SHA/AES/DES/RSA.

Support

  • The ways in which encoding/encryption can be performed are:
      • MD5
      • SHA-1/SHA-256
      • AES
      • DES
      • RSA
  • The methods that can be decrypted are:
      • AES
      • DES
      • RSA

Import registration

Import dependencies

Introduce dependencies in the project's pom.xml:

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

Enable component

  • Add the @EnableEncryptBody annotation to the Application class corresponding to the project, such as:
@EnableEncryptBody
@SpringBootApplication
public class Application {
    
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

Configuration parameters

Add parameter configuration in the application.yml or application.properties file of the project, for example:

encrypt:
    body:
      aes-key: 12345678 #AES encryption key
      des-key: 12345678 #DES encryption key
      # more...

Use

Valid for the entire controller

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

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

}

Valid for a single request

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

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

}

Effective on the declared class of the response

@Data
@EncryptBody
public class User implements Serializable {

    private String name;

    private String email;

    private Integer number;

    private String numberValue;

}

Effective for a single attribute of the declared class

@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;

}

Annotation list

License

Apache 2.0