Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

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

Chilkat2 Java
import com.chilkatsoft.chilkat2.PrivateKey;
import com.chilkatsoft.chilkat2.Rsa;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        PrivateKey pkey = new PrivateKey();
        Rsa rsa = new Rsa();
        rsa.genKey(1024, pkey);
        rsa.usePrivateKey(pkey);

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

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

        System.out.println(strSig);
    }
}