Encode Decode Byte Array To Base64 String Using Java

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading ... Loading ...

The code uses non standard classes found in the sun.misc package to convert to and from Base64. These classes may change in the future. Taken from Example Depot.

1
2
3
4
5
6
 // Convert a byte array to base64 string
byte[] buf = new byte[]{0x12, 0x23};
String s = new sun.misc.BASE64Encoder().encode(buf);
 
// Convert base64 string to a byte array
buf = new sun.misc.BASE64Decoder().decodeBuffer(s);
Bookmark and Share

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.

Related Posts with Thumbnails

Leave a Reply