Deterministic Base64 support
See original GitHub issueThis issue is being created to supersede similarly reported issues and represent a canonical issue to enable the following:
-
Check to see if
java.util.Base64
is available at runtime usingClasses.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 -
If
java.util.Base64
is not available:-
If the runtime enviornment is Android, use android.util.Base64. This is available on Android API level >= 8 (i.e. >= Android 2.2, “Froyo”)
-
Otherwise, assume < JDK8, and use
javax.xml.bind.DatatypeConverter
. JDK 7 has this included automatically.
-
-
In any case, enable
JwtBuilder
andJwtParser
methods that allow a user to specify their own Base64TextCodec
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. -
Ensure any codec implementation will throw exceptions on invalid inputs when possible. See #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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (16 by maintainers)
Top GitHub Comments
This has been released in 0.10.0.
@azagniotov I’ve used migbase64 in production environments before, so I’m not too worried about that. That said, I’m adding tests for it anyway to ensure we still keep 100% coverage.