-
Notifications
You must be signed in to change notification settings - Fork 345
使用文档
尹吉欢 edited this page May 3, 2022
·
14 revisions
第一步:增加项目依赖
<dependency>
<groupId>com.cxytiandi</groupId>
<artifactId>monkey-api-encrypt-core</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
第二步:配置加解密过滤器(Spring Boot中配置方式)
@Configuration
public class FilterConfig {
@Bean
public FilterRegistrationBean<EncryptionFilter> filterRegistration() {
EncryptionConfig config = new EncryptionConfig();
config.setKey("d86d7bab3d6ac01ad9dc6a897652f2d2");//1.2版本及以下key 16位,1.2以上key 32位
config.setRequestDecyptUriList(Arrays.asList("/save", "/decryptEntityXml"));
config.setResponseEncryptUriList(Arrays.asList("/encryptStr", "/encryptEntity", "/save", "/encryptEntityXml", "/decryptEntityXml"));
FilterRegistrationBean<EncryptionFilter> registration = new FilterRegistrationBean<EncryptionFilter>();
registration.setFilter(new EncryptionFilter(config));
registration.addUrlPatterns("/*");
registration.setName("EncryptionFilter");
registration.setOrder(1);
return registration;
}
}
- EncryptionConfig EncryptionConfig是加解密的配置类,配置项目定义如下:
public class EncryptionConfig {
/**
* AES加密Key,长度必须16(1.2版本及以下key 16位,1.2以上key 32位)
*/
private String key = "d86d7bab3d6ac01ad9dc6a897652f2d2;
/**
* 需要对响应内容进行加密的接口URI<br>
* 比如:/user/list<br>
* 不支持@PathVariable格式的URI
*/
private List<String> responseEncryptUriList = new ArrayList<String>();
/**
* 需要对请求内容进行解密的接口URI<br>
* 比如:/user/list<br>
* 不支持@PathVariable格式的URI
*/
private List<String> requestDecyptUriList = new ArrayList<String>();
/**
* 响应数据编码
*/
private String responseCharset = "UTF-8";
/**
* 开启调试模式,调试模式下不进行加解密操作,用于像Swagger这种在线API测试场景
*/
private boolean debug = false;
}