I understand that this is probably a more general Java issue, but since it works in the Notes \ Domino environment, I thought I checked this community first.
Summary:
It seems I can not decode the string: dABlAHMAdAA = using lotus.domino.axis.encoding.Base64 or sun.misc.BASE64Decoder
I know the source: test
I confirmed by decoding at http://www5.rptea.com/base64/ , it looks like UTF-16.
As a simple test using any of the following:
String s_base64 = "dABlAHMAdAA="; byte[] byte_base64 = null; String s_decoded = ""; byte_base64 = new sun.misc.BASE64Decoder().decodeBuffer(s_base64); s_decoded = new String(byte_base64, "UTF-16"); System.out.println("Test1: " + s_decoded); byte_base64 = lotus.domino.axis.encoding.Base64.decode(s_base64); s_decoded = new String(byte_base64, "UTF-16"); System.out.println("Test2: " + s_decoded); System.out.println("========= FINISH.");
I get the output:
Test1: ???? Test2:
If I create a String as UTF-8
s_decoded = new String(byte_base64, "UTF-8");
output:
t
the error is not thrown, but the code does not complete, does not reach "FINISH".
Detail
I am accessing the asmx web service, in the SOAP response some nodes contain base64 encoded data. There is currently no way to change the service, so I need XPath and decrypt myself. The encoded data is text or html. If I transfer the encoded data through http://www5.rptea.com/base64/ and select UTF-16, it decodes correctly, so I have to do something wrong.
As a side note, I encoded a βtestβ:
s_base64 = lotus.domino.axis.encoding.Base64.encode(s_text.getBytes()); System.out.println("test1 encodes to: " + s_base64); s_base64 = new sun.misc.BASE64Encoder().encode(s_text.getBytes()); System.out.println("test2 encodes to: " + s_base64);
they both encode:
dGVzdA == ... which, if you then feed 2 decoders above, as expected, decodes correctly.
If I go to the site above and encode the βtestβ as UTF-16, I get: dABlAHMAdAA = to confirm that the data is in UTF-16.
This is similar to the fact that the data is genuine base64 data, but the decoder does not recognize them as such. I'm a bit stumped.
Any pointers or comments would be greatly appreciated.