Base 64 Encoidng and Decoding

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import org.apache.commons.codec.binary.Base64;

String strTobeEncoded = "This is message body which will be 64 encoded";
String strTobeDecoded = "VGhpcyBpcyBtZXNzYWdlIGJvZHkgd2hpY2ggd2lsbCBiZSA2NCBlbmNvZGVk";

String encodedResult = "";
String decodedResult = "";

try
{
 // encoding using sun.misc.BASE64Encoder;
 BASE64Encoder encoder = new BASE64Encoder();
 encodedResult = encoder.encode(strTobeEncoded.getBytes());
 System.out.println("Encoded by Sun's encoder: " + encodedResult);

 // decoding using sun.misc.BASE64Encoder;
 BASE64Decoder decoder = new BASE64Decoder();
 decodedResult = new String(decoder.decodeBuffer(strTobeDecoded));
 System.out.println("Decoded by Sun's decoder: " + decodedResult);

 // encoding using org.apache.commons.codec.binary.Base64;
 encodedResult = new String(Base64.encodeBase64(strTobeEncoded.getBytes()));
 System.out.println("Encoded by Apache's encoder: " + encodedResult);

 // encoding using org.apache.commons.codec.binary.Base64;
 decodedResult = new String(Base64.decodeBase64(strTobeDecoded.getBytes()));
 System.out.println("Decoded by Apache's decoder: " + decodedResult);
}
catch (Exception e)
{
}