Encode Decode Byte Array To Base64 String Using Java


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);

Found this post useful? Buy me a cup of coffee or subscribe to my RSS feeds and Google Friend Connect

Related Posts with Thumbnails

Leave a Reply

Spam protection by WP Captcha-Free