Nov 15

Java includes an undocumented class, sun.misc.BASE64Encoder, for handling Base64 encoding. The following gives an example of its usage.


byte[] bytes = getBytesFromSomewhere();

// Create encoder

BASE64Encoder encoder = new BASE64Encoder();

// Create encoded string from supplied byte array

String encoded = encoder.encode(bytes);

There are lots of other encoders available if you don’t want to use that one.

written by objects \\ tags: ,

Nov 15

Java includes an undocumented class, sun.misc.BASE64Decoder, for handling Base64 decoding. The following gives an example of its usage.


String encoded = getEncodedStringFromSomewhere();

// Create encoder

BASE64Decoder decoder = new BASE64Decoder();

// Decode encoded string into original byte array

byte[] decoded = decoder = decoder.decodeBuffer(encoded);

written by objects \\ tags: , ,