0

In my spring webapp I am receiving an HTTP header with RC4 encrypted string. When I decrypt this after taking the value from header I am getting wrong string. Following is the code excerpts from spring controller class.What is the default decoding done in the request.getheader() method. how can I use any other decoding?

Following is the tcp trace screenshot showing header key and value.

screenshot of tcptrace

byte[] enc_msisdn = request.getHeader(headerName).getBytes();
rc4 = new RC4("rc4pskey".getBytes());
byte[] decipher = rc4.decrypt(enc_msisdn);
Niyasim
  • 76
  • 5
  • Is your actual key representable in 7-bit ASCII? If not, you might have character encoding issues because you aren't explicitly specifying the charset. – Andy Turner Jun 11 '17 at 10:01
  • Thanks Andy.the value i want to retriev from header wil be something like this " sN vÎÙÀ¸ëÝV ". How can i explicitly specify which decoding to use while taking value from getHeader() method. – Niyasim Jun 11 '17 at 11:44
  • (That's an outrageous value for a HTTP header.) You may want to try `ISO-8859-1` as per https://stackoverflow.com/questions/4400678/what-character-encoding-should-i-use-for-a-http-header#4410331. Failing that, UTF-8 may be worth trying too. Any knowledge that you have of the source of the request might give you further ideas to try. – shinobi Jun 11 '17 at 12:04
  • unfortunately yes. We are using this to get the RC4 encrypted value of mobile number for security reason. I am updating my question with screenshot showing the value i can see in the tcp trace. Appreciate your support. – Niyasim Jun 11 '17 at 12:55
  • For what it's worth, `iconv` accepts the sequence as `ISO-8859-1` – shinobi Jun 11 '17 at 17:04
  • So,is there any way to UTF-8 decode the header value string in java with the **request** object? – Niyasim Jun 12 '17 at 11:58

0 Answers0