I'm having problems decoding a byte[] to string following a tutorial... This is my code:
import java.util.Base64;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class Main
{
private static final Charset UTF_8 = StandardCharsets.UTF_8;
public static void main(String[] args) {
String text = "hello";
System.out.println("Original text: " + text);
byte[] aesByte = text.getBytes(UTF_8);
System.out.println("Original text in byte[]: " + aesByte);
String encoded = Base64.getEncoder().encodeToString(aesByte);
System.out.println("Encode original text from byte[] to String: " + encoded);
byte[] decoded = Base64.getDecoder().decode(encoded);
System.out.println("Decode string to byte[] of original text: " + decoded);
}
}
This is the output:
Original text: hello
Original text in byte[]: [B@2a139a55
Encode original text from byte[] to String: aGVsbG8=
Decode string to byte[] of original text: [B@15db9742
Isn't suppose to work?