Sample code for 30+ languages & platforms
Java

Base64 Encode/Decode a String

See more Encryption Examples

_LANGUAGE_ example to base-64 encode and decode a string.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkBinData bd = new CkBinData();

    String s = "A friend called me up the other day and talked about investing in a dot-com that sells lobsters. Internet lobsters. Where will this end? --Donald Trump";

    success = bd.AppendString(s,"utf-8");

    String strBase64 = bd.getEncoded("base64");
    System.out.println(strBase64);

    // To decode:
    CkBinData bd2 = new CkBinData();
    bd2.AppendEncoded(strBase64,"base64");

    String decoded = bd2.getString("utf-8");
    System.out.println(decoded);
  }
}