yinjihuan / monkey-api-encrypt Goto Github PK
View Code? Open in Web Editor NEWmonkey-api-encrypt是对基于Servlet的Web框架API请求进行统一加解密操作
License: Apache License 2.0
monkey-api-encrypt是对基于Servlet的Web框架API请求进行统一加解密操作
License: Apache License 2.0
1、在测试接口的时候,没有对请求参数进行加密,依然可以请求和响应,建议加上属性,可以标识是否强制界面
2、注解的位置可以放到请求参数那块吗?类似@requestbody一样,改成@target(ElementType.PARAMETER)一样的
spring-boot-starter-encrypt not supoort gradle?
请求返回数据的加密,到客户端(浏览器)还是要解密,那就意味着解密算法是要放到浏览器上,这样别人完全可以拿到解密算法自己来进行数据的加解密,这个和混淆压缩等方式类似把,只能在一定程度上增加爬接口的难度,并不能完全避免呀
写了自定义加密过滤器和加密算法
网站https启用,这里加密对中文无法解密,出现乱码
按照DEMO中的RSA自定义算法进行配置后,前端使用什么工具进行RSA加密的喃?现目前我前端使用了JSEncrypt进行加密和解密,但是使用后端生成的公钥和密钥都无法进行加解密,仔细看了一下,后端生成的加密结果是256位,然而前端加密出来的只有127位,请赐教!谢谢!
你在主页中说:
js加密文件请参考我GitHub中encrypt中的aes.js,crypto-js.js,pad-zeropadding.js
能否直接发地址?我真的在你github找半天也没找到。
谢谢
最进用到了你的项目,发现自动解密@RequestParam参数无值,然后尝试自己手动添加,由于是引得第三方依赖,为了减少耦合,已提交自己github仓库中,希望能参考下
关于两个/的问题
是自己的项目中配置了
server.servlet.context-path=/
就会显示两个/
项目地址
是否可以修改下加密范围,使得使用graphql的servlet时也可以加密数据
首先很感谢作者的开源,不过不得不说,使用文档里的依赖中的加解密默认工具,解密使用的是默认系统默认编码,没有使用制定编码。最新的代码中是有修改这个问题的,想快速使用的时候没成功,还是要跟一下代码。
发送数据之后,后台异常:
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
at com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:975) ~[sunjce_provider.jar:1.8.0_231]
at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1056) ~[sunjce_provider.jar:1.8.0_231]
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853) ~[sunjce_provider.jar:1.8.0_231]
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446) ~[sunjce_provider.jar:1.8.0_231]
at javax.crypto.Cipher.doFinal(Cipher.java:2164) ~[na:1.8.0_191]
at com.cxytiandi.encrypt.util.AesEncryptUtils.aesDecryptByBytes(AesEncryptUtils.java:37) ~[monkey-api-encrypt-core-1.2.RELEASE.jar:na]
at com.cxytiandi.encrypt.util.AesEncryptUtils.aesDecrypt(AesEncryptUtils.java:42) ~[monkey-api-encrypt-core-1.2.RELEASE.jar:na]
at com.cxytiandi.encrypt.algorithm.AesEncryptAlgorithm.decrypt(AesEncryptAlgorithm.java:20) ~[monkey-api-encrypt-core-1.2.RELEASE.jar:na]
at com.cxytiandi.encrypt.core.EncryptionFilter.processDecryption(EncryptionFilter.java:154) ~[monkey-api-encrypt-core-1.2.RELEASE.jar:na]
... 35 common frames omitted
response.setContentLength(responseData.length());
如果response有中文时会有问题
这个地方应该使用responseData.getBytes(encryptionConfig.getResponseCharset())
的length
作者你好,遇到一个问题,在将解密后的字符串放到request中时:reqestWrapper.setRequestData(decyptRequestData);
在controller层遇到了Required request body is missing的问题,导致无法接收到正确参数。
我是参考实现,是我对什么地方没有处理导致的么?
@RequestMapping(value = "/", method = RequestMethod.POST) 其中value为空或者为/时报错:
"JSON parse error: Unrecognized token 'wMMsvm2p': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'wMMsvm2p': was expecting ('true', 'false' or 'null')↵ at [Source: (PushbackInputStream); line: 1, column: 10]"
在源码ApiEncryptDataInit类中处理requestMapping注解时,见下面源码:
} else if (null != requestMapping) {
RequestMethod m = requestMapping.method()[0];
methodType = m.name().toLowerCase() + ":";
uri.append(formatUri(requestMapping.value()[0]));
}
直接取的requestMapping.method()[0],此时会取不到请求的method,将会报数组越界!请fixed! 嘿嘿
微服务架构采用feign调用,服务与服务之间的调用处理不需要进行报文加减密;面对这种情况,大神有什么思路过滤掉吗
你好,我集成@EnableEncrypt //启用加密Starter 的时候,原本我使用了solrj,在启动类中加了@SpringBootApplication(exclude = SolrAutoConfiguration.class)这个注解,在新增了@EnableEncrypt 之后我的项目启动的时候报如下错(不加@EnableEncrypt之前项目正常运行):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrClient' defined in class path resource [org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.solr.client.solrj.SolrClient]: Factory method 'solrClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrClient$Builder
因为restful风格,PostMapping里面没有url,导致ApiEncryptDataInit初始化的时候执行到getApiUri方法是,会报数组下标越界
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at com.cxytiandi.encrypt.springboot.init.ApiEncryptDataInit.getApiUri(ApiEncryptDataInit.java:176)
您好,对于非对称加密的算法会生成一对公私钥,EncryptAlgorithm接口现在只支持传一个key,我现在的做法是扩展原有配置类的字段存放秘钥对,然后在EncryptAlgorithm的实现类中直接调用,这样接口中的第二个参数就可以去掉了
在全局开启加解密debug=false
的情况下,需要局部排除一些比较麻烦,(比如swagger2),是否可增加如上注解以忽略加解密?
对get的请求加密支持请问有时间表吗?
@Override
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
this.contextPath = ctx.getEnvironment().getProperty("server.servlet.context-path");
Map<String, Object> beanMap = ctx.getBeansWithAnnotation(RestController.class);
initData(beanMap);
beanMap = ctx.getBeansWithAnnotation(Controller.class);
initData(beanMap);
}
这段代码通过@controller注解获取的Controller只有一部分,没获取到我项目里的api接口Controller,导致@Encrypt注解无效。请问这种情况是什么原因?
使用@ControllerAdvice进行统一处理时,项目中有一个异常全局拦截也使用了@ControllerAdvice,异常拦截会失效
Thank you for the code. But while running the projecting and using the annotation @decrypt. I am getting BadPaddingException. Would really appreciate if you can help me out on this.
推测,shiro对request进行过一次包装,对request的inputStream读过一次所以这个再去读的时候为空了...解码错误
调用filter链的chain.doFilter()将请求转发给下一个filter 如果在拦截url向前端返回数据时使用了printWriter 会和servletOutputStream 冲突报错 IllegalStateException
现在没有对JSON 加密,对JSON 机密后也可以解密,但是报错json解析错误
JSON parse error: No content to map due to end-of-input; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input\n at [Source: UNKNOWN; line: 1, column: 0]
老师,你好,对于数据安全性你这样做完全没有问题,但是对于XSS攻击的话,用注解的形式不好实现的吧!
springboot使用注解方式,配置context-path导致加、解密无法使用
Springboot中加上了加解密的注解但是好像没有起作用,filter里面直接就跳过了加解密的过程
用Spring AOP切入Controller后,加解密注解失效
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>
<!--数据传输加密解密--> <!-- https://github.com/yinjihuan/spring-boot-starter-encrypt --> <dependency> <groupId>com.cxytiandi</groupId> <artifactId>spring-boot-starter-encrypt</artifactId> <version>1.0</version> </dependency>
Dependency 'com.cxytiandi:spring-boot-starter-encrypt:1.0' not found less... (Ctrl+F1)
Inspection info: Inspects a Maven model for resolution problems.
不支持 /encryptEntity/{parm} 这种方式的加解密啊
后端返回的数据还是的json格式.目前返回的是String类型,前端在response接收到之前 会报一个js的JSON.parse的错误.
补充CryptoJS的引入:
var CryptoJS = require("crypto-js");
使用@RequestParam参数来接收参数,是无法解密的,只有用@requestbody的时候才可以。还有就是如果我统一了返回数据格式,就像:{code:““,msg:"",data:""},把他们全部加密好像有点多余,只加密data部分是不是更好点。
server-servlet-ontext-path= /api
需要在
config.setRequestDecyptUriList(Collections.singletonList("/api/user"));
是这样吗?
您好,如果不用固定的key,需要随机生成aes加密key 是重写EncryptionConfig这个类就可以吗
后端返回数据显示加密成功,前端解密时出现异常
crypto-js.js:460 Uncaught (in promise) Error: Malformed UTF-8 data
建议添加一下Maven支持
这样直接解析输入流,后面的程序还能获得么??
我观察到AesEncryptUtils这个类用的填充策略是Pcks5来解密的。前端用的是Pcks7来解密的。我用AesEncryptUtils类来解密加密的字符串没有问题,但是用前端Pcks7的填充策略去解密,解密不成功。请问是两者填充策略的问题吗?
spring:
encrypt:
key: ***
debug: true
jar内有一个过滤器Filter,貌似没用上?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.