import org.apache.commons.codec.binary.Base64;

* @author Meihta Dwiguna Saputra

public class Main
    public static void main(String[] args)
        String name = "Meihta Dwiguna Saputra";
        String encodeResult = new Main().encodeBase64(name);
        String decodeResult = new Main().decodeBase64(encodeResult);
        System.out.println("Encode Result = " + encodeResult);
        System.out.println("Decode Result = " + decodeResult);

    private String encodeBase64(String stringToEncode)
        return Base64.encodeBase64String(stringToEncode.getBytes());

    private String decodeBase64(String base64ToDecode)
        return new String(Base64.decodeBase64(base64ToDecode.getBytes()));

Here is result if we run the program :

NB : You need apache common-codec library to use code above, also if you found exception or error,  do not worry, it means the library have dependency injection from another apache library, by find and add dependency injection it should be work properly. 😉