Base64URL for Java
Looking for a good and well documented Java library for Base64url encoding + decoding?
Apache Commons Codec does it: http://commons.apache.org/codec/
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).