Skip to content

Deterministic Base64 support #333

Closed
Closed
@lhazlewood

Description

@lhazlewood

This issue is being created to supersede similarly reported issues and represent a canonical issue to enable the following:

  1. Check to see if java.util.Base64 is available at runtime using Classes.isAvailable (or similar), and if so, use that. This is the best/fastest one available to most default environments and should be used whenever possible.

    java.util.Base64 is available on JDK >= 8 and Android level >= 26

  2. If java.util.Base64 is not available:

    1. If the runtime enviornment is Android, use android.util.Base64. This is available on Android API level >= 8 (i.e. >= Android 2.2, "Froyo")

    2. Otherwise, assume < JDK8, and use javax.xml.bind.DatatypeConverter. JDK 7 has this included automatically.

  3. In any case, enable JwtBuilder and JwtParser methods that allow a user to specify their own Base64 TextCodec if/when desired, e.g. Jwts.parser().setBase64Codec(myBase64Codec) This last option would allow the user to enable Base64 support in any environment that doesn't match 1 and 2 above.

  4. Ensure any codec implementation will throw exceptions on invalid inputs when possible. See Consider using a different Base64 decoder #143 as an example. Exceptions should be thrown when possible to indicate invalid input, wrapping/propagating the original codec exception.

Implementation note: Perhaps instead of using javax.xml.bind.DatatypeConverter - which doesn't always fail on invalid inputs (see #143), we should embed the Commons Codec or MigBase64 implementation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions