使用方法
Apache Maven
Gradle Groovy DSL
implementation 'cn.shuibo:rsa-encrypt-body-spring-boot:1.0.1.RELEASE'
以Maven为例,在pom.xml中引入依赖
启动类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:
open: true # 是否开启加密 true or false
showLog: true # 是否打印加解密log true or false
publicKey: # RSA公钥
privateKey: # RSA私钥
对返回值进行加密
@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();
}
上一篇 crypto加密解密模块
下一篇 Java加密和解密算法调用工具包