xor使用sprint引导过滤器解密httpservletrequest

bfnvny8b  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(190)

我试图找到一种使用JavaSpringBootFilter(onceperrequestfilter)对有效负载进行xor解密的方法

@Component
public class XorDecryptFilter extends OncePerRequestFilter {

  private static final Logger LOG = LoggerFactory.getLogger(XorDecryptFilter.class);
  public static final String CONTENT_ENCODING = "content-encoding";
  public static final String GZIP = "gzip";
  public static final String UTF_8 = "UTF-8";

  @Override
  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    if (isShouldDecrypted(request)) {
      XorHttpServletRequestWrapper xorHttpServletRequestWrapper = new XorHttpServletRequestWrapper(request);
      filterChain.doFilter(xorHttpServletRequestWrapper, response);
    }
    else {
      filterChain.doFilter(request, response);
    }
  }

请求 Package 器:

public static class XorHttpServletRequestWrapper extends HttpServletRequestWrapper {

    private XorInputStream xorInputStream;

    public XorHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
      super(request);
      try {
        xorInputStream = new XorInputStream(request.getInputStream());
      }
      catch (IOException ex) {
        LOG.error("failed to create gzip input stream. content-encoding is {}", request.getHeader(CONTENT_ENCODING));
        throw ex;
      }
    }

    @Override
    public ServletInputStream getInputStream() throws IOException {
      return new XorDecryptFilter.DelegatingServletInputStream(xorInputStream);
    }

    @Override
    public BufferedReader getReader() throws IOException {
      return new BufferedReader(new InputStreamReader(xorInputStream, UTF_8));
    }
  }

实际上,我需要帮助来实现xorinputstream类;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题