1

I have the following base 64 encoded string:

e4EdYQYDTpC7sN0K87elHA==

In Window.Atob in javascript it provides me with {aN»°Ý ó·¥ however when running the below code in Java it gives me

{�aN����
�

String encodedString = "e4EdYQYDTpC7sN0K87elHA==";
Decoder decoder = Base64.getDecoder();
byte[] decodedByte = decoder.decode(encodedString);
String decodedString = new String(decodedByte);
System.out.println(decodedString);

As you can see the output is extended ascii but I cannot seem to replicate the results of Window.atob in java.

The Byte output from Java is:

123
-127
29
97
6
3
78
-112
-69
-80
-35
10
-13
-73
-91
28

While the output should be:

123 194 129 029 097 006 003 078 194 144 194 187 194 176 195 157 032 195 179 194 183 194 165 028

Any ideas on what needs to be done in order to replicate the result.

Charabon
  • 737
  • 2
  • 11
  • 23
  • 2
    Why the javascript tag? Javascript is **not** the same or closely related to Java and seems to be out of context on this question. – Filnor Sep 18 '17 at 09:18
  • I have removed it however included it on the basis of using Window.atob which seems to be giving me desired results – Charabon Sep 18 '17 at 09:26
  • Try this code. `byte[] message = "e4EdYQYDTpC7sN0K87elHA==".getBytes(StandardCharsets.UTF_8); String encodedString = Base64.getEncoder().encodeToString(message);` by replacing the first line of your code. – Procrastinator Sep 18 '17 at 09:29

0 Answers0