Base64url for Java

Looking for a good and well documented Java library for Base64url encoding + decoding?

Apache Commons Codec does it:

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

// to encode into Base64url
byte[] b64data = Base64.encodeBase64URLSafe(binaryData);

// to decode a Base64url
byte[] binaryData = Base64.decode(b64data);

Base64url was created to allow safe use of base64 encoded data in URL strings. This is done by avoiding ‘=’ padding at the end and emitting ‘-‘ and ‘_’ instead of the usual ‘+’ and ‘/’ characters.

Base64url is used to encode JSON Web Tokens (JWT).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>