简体中文 | English
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.
- 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
-
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>
- Add the
@EnableEncryptBody
annotation to theApplication
class corresponding to the project, such as:
@EnableEncryptBody
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
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...
@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;
}