import org.apache.commons.codec.binary.Base64;
We can not use sun.* packages for Base64 encoding, because this package is not a part of supported public interface.
byte[] encodedBytes = Base64.encodeBase64("sample".getBytes());
System.out.println("encodedBytes " + new String(encodedBytes));
byte[] decodedBytes = Base64.decodeBase64(encodedBytes);
System.out.println("decodedBytes " + new String(decodedBytes));