# encrypt-api-spring-boot **Repository Path**: fajia/encrypt-api-spring-boot ## Basic Information - **Project Name**: encrypt-api-spring-boot - **Description**: 基于spring boot api接口加解密 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-02-26 - **Last Updated**: 2023-08-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: SpringBoot ## README ### 1.介绍 **rsa-encrypt-body-spring-boot** Spring Boot接口加密,可以对返回值、参数值通过注解的方式自动加解密 。 ### 2.使用方法 - **启动类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 // 开启响应加密 @PostMapping("/test") public ResultDto encryptTest(@EncParam String name, @EncParam Integer age) { System.out.printf("解密后的姓名与年龄:%s,%s",name,age); User user = new User(); user.setName("lfj"); user.setAge(30); ResultDto resultDto = new ResultDto<>(); resultDto.setData(user); return resultDto; } ```