我正在尝试加密从我的 Web 应用程序发送到我的服务的 POST 正文请求。
加密是在过滤器中完成的。
我面临内容长度的问题,内容长度是在 JavaScript
中为 post 调用设置的,并且在加密完成后在过滤器中设置,内容长度发生变化(长度增加)以及何时发布数据被传输到服务,数据被 chop 为最初(加密前)数据的长度,这使得数据不可用。
加密代码:
public void jsonEncrypt(String passPhrase, int iterationCount, int keySize, String salt, String initializationVector) throws IOException {
String json = new String(body, StandardCharsets.UTF_8);
AesUtil aesUtil = new AesUtil(keySize, iterationCount);
encryptJsonText = aesUtil.encrypt(salt, initializationVector, passPhrase, json);
byte[] b = encryptJsonText.getBytes();
body = b;
}
最佳答案
我能够解决覆盖 getContentLength()
方法以返回新长度的问题。通过此,我能够加密请求正文并将其发送到我的服务,并在其中解密 body 并使用它。
关于javascript - 如何更改过滤器中的 servletRequest 内容长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36700229/