0

I am using JBOSS 4.2.3 and UsernamePasswordLoginModule class being extended by custom class which overrides method validatePassword. This method has two parameters inputPassword and expectedPassword. Client sends Base64 encoded loginId:password to the server and server decodes using base64. Server decodes credentials using iso-8859-1 (I verified after looking accented characters on online conversion tool and that was equivalent to iso output not UTF-8). Since iso does not supports international characters and I need to use UTF-8 but I did not figure it out where this iso encoding has done if we are doing Base64 decode. I searched Base64 decode method but charset was not specified.

My query is that do we have any mechanism to set encoding in above said scenario. Requirement is that client will send UTF-8 data and I need to decode using UTF8. Thanks in advance.

sukhi
  • 904
  • 7
  • 11

1 Answers1

0

Base64 encoding and decoding of strings is a two step process:

[Encoding] String -> byte[] -> String (base64 encoded)
[Decoding] String (base64 encoded) -> byte[] -> String

The character encoding needs to be set in the steps highlighted in bold.

For encoding that would mean doing:

String s;
byte[] bytes = s.getBytes("UTF-8");

For decoding it would be:

byte[] bytes;
String s = new String(bytes, "UTF-8");
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156