Sample code for 30+ languages & platforms
Java

Base64url Encoding

See more Encryption Examples

Base64url encoding is identical to base64 encoding except it uses non-reserved URL characters (e.g. '–' is used instead of '+', and '_' is used instead of '/') and it omits the padding characters.

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;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkPrivateKey pkey = new CkPrivateKey();
    CkRsa rsa = new CkRsa();
    rsa.GenKey(1024,pkey);
    rsa.UsePrivateKey(pkey);

    String strData = "This is the string to be signed.";

    // Get the signature in base64url
    rsa.put_EncodingMode("base64url");
    String strSig = rsa.signStringENC(strData,"sha256");

    System.out.println(strSig);
  }
}