I have a String
variable say string
that I converted into byte[]
and then I encoded the same using Base64
in as byte[]
say encodedByteArr
. Using the below code:
String string = "Test";
byte[] encodedByteArr= null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(check);
encodedByteArr= Base64.encodeBase64(bos.toByteArray());
oos.flush();
oos.close();
bos.close();
System.out.println("Encoded value is:- "+encodedByteArr);
Output is:
Encoded value is:- [B@5fd0d5ae
Now, I receive the same encoded value in another method as a String
, which means:
String string = "[B@5fd0d5ae";
And it is nothing but a String
representation of byte[]
which I generated in above code.
Now my task is to actually decode the value and get back the original text back, that is "Test"
.
And for that, I want the String
representation of byte[]
back to a an byte[]
without losing its integrity.