1.介绍
rsa-encrypt-body-spring-boot
实现了对Spring Boot接口返回值、参数值通过注解的方式自动加解密。
2.使用方法
- 在pom.xml中引入依赖
<dependency>
<groupId>cn.shuibo</groupId>
<artifactId>rsa-encrypt-body-spring-boot</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
- 启动类Application中添加@EnableSecurity注解
@SpringBootApplication
@EnableSecurity
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
- 在application.yml或者application.properties中添加RSA公钥及私钥
rsa:
encrypt:
debug: false # true表示开启调试,不加密。(方便开发时测试)
publicKey: 123456
privateKey: 123456
- 对返回值进行加密
@Encrypt
@GetMapping("/encryption")
public TestBean encryption(){
TestBean testBean = new TestBean();
testBean.setName("shuibo.cn");
testBean.setAge(18);
return testBean;
}
- 对传过来的加密参数解密
@Decrypt
@PostMapping("/decryption")
public String Decryption(@RequestBody TestBean testBean){
return testBean.toString();
}
3.About author
- Blog:https://shuibo.cn
- QQ群:7277991 点击加入