针对SpringBoot项目中的参数传递使用RSA加密机制保证安全性进行封装成工具

spring-boot-starter-security


1 概述

针对SpringBoot项目中的参数传递使用RSA加密机制保证安全性进行封装成工具,实现自动加密返回数据、解密传入数据并映射成json

2 使用 

这里的使用就比较简单了。
(1)将工具导入项目中。
(2)在配置文件application.properties中添加配置内容。

spring.encrypt.privateKey=MIICdgIB....
spring.encrypt.debug=false
上面的主要功能就是添加RSA加密和解密的私钥,并且将debug开关置为false(如果置为true将不会进行加密和解密操作)。

使用步骤参考:SpringBoot--RSA自动加密解密工具

(3)在启动类上添加EnableSecurity注解

@SpringBootApplication
@ComponentScan(basePackages={"com.liutao.swagger"})
@EnableSecurity
public class Application {
 
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

(4)在需要加密的方法上添加Encrypt注解(解密为Decrypt)

@Encrypt
    @ApiOperation(value="获取用户")
    @GetMapping("user")
    public User getUser(){
        User user = new User();
        user.setName("liutao");
        user.setId("1212");
        user.setPassword("123456");
        return user;
    }

运行代码,我们就可以看见自动解密和加密工具生效。


来源于:

https://github.com/liutao910612/TOOL_SpringBootSecurityStater

猜你喜欢

转载自blog.csdn.net/weixin_41888813/article/details/83998380