Does anyone know how to decode and encode a string in Base64 using the Base64. I am using the following code, but it's not working.
String source = "password";
byte[] byteArray = source.getBytes("UTF-16");
Base64 bs = new Base64();
//bs.encodeBytes(byteArray);
System.out.println( bs.encodeBytes(byteArray));
//bs.decode(bs.encodeBytes(byteArray));
System.out.println(bs.decode(bs.encodeBytes(byteArray)));
Best Answer
First:
Transmitting end:
text.getBytes(encodingName)
)Base64
classReceiving end:
Base64
classnew String(bytes, encodingName)
)So something like:
Or with
StandardCharsets
: