java - MD5 Signing a HttpServletResponse -
I'm looking for a way to inspect the contents of a HttpServletResponse
MD5 hash
Pseudocode can look like this
process (reply response, request request) {defaultProcessingFor (response, request); Dispatcher.handle (feedback, request); // Here I want to read the contents of the response object (now filled with data) so that the MD5 hash can be prepared with them and it should be added to a header. }
Is this possible?
Yes, this is possible. You need to decorate the response with the help in which you replace it with a custom implementation that writes the byte to both the MD5 digest and the "basic" outstream stream. Finally provide an accessor to get the last MD5 amount.
Update I just went a little bit for fun, here's a kickoff example:
Response Casing:
Public Sector MD5ServletResponse HttpServletResponseWrapper Extended {Private Ultimate MD5ServletOutputStream Output; Personal Final Prints Author Writer; Public MD5ServletResponse (HttpServletResponse Response) throws IOException {super (feedback); Output = new MD5ServletOutputStream (response.getOutputStream ()); Author = new printwire (output, true); } Public PrintWriter getWriter () throws IOException {return author; } Public ServletOutputStream getOutputStream () throws IOException {return output; } Public byte [] getHash () {return output.getHash (); }}
MD5 Outstream:
How to use it:
// Wrap the original response with it: MD5ServletResponse md5response = New MD5ServletResponse (feedback); // Now simply use md5response or feedback, eg: dispatcher.handle (request, md5response); // then get hashes, eg: byte [] hash = MD5 RSS Stringbillder hash ashxstring = new stringbirder (hash lamp * 2); (Byte B: for hash) {hashxhoststring.epend (string format ("% 02x", b)); } System.out.println (hashxhxstring); // example af28cb895a479397f12083d1419d34e7
Comments
Post a Comment