简体中文 | 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.yml
或application.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;
}