Consider switching base64 codec to http://migbase64.sourceforge.net/

Issue #63 resolved
Vladimir Dzhuvinov created an issue

Comments (6)

  1. Vladimir Dzhuvinov reporter

    migbase64 doesn't support URL-safe encoding and decoding.

    The URL-safe encoding can be added with little effort. The decoding, however, will require more work.

  2. Marc Powell

    In our implementation with migbase64, we did a simple string replace for the characters:

    Base64URL:

        public static Base64URL encode(final byte[] bytes) {
            return new Base64URL(util.Base64.encodeToString(bytes,false).replace('+','-').replace('/','_'));
        }
    

    Base64:

        public byte[] decode() {
            return util.Base64.decode(value.replace('-','+').replace('_','/'));
        }
    

    However, once caveat is that the migbase64 decode method always expects padding (len divisible by 4) whereas with the original apache codec version it was optional.

  3. Vladimir Dzhuvinov reporter

    Thanks for the suggestion.

    I added an URL-safe alphabet to the Mig code, see commit a6f1ef8. The decoding will indeed be trickier to modify to accept non-padded strings. The author has a routine at the beginning that precomputes the resulting array and that has to be modified to work in both cases (with and without padding).

  4. Vladimir Dzhuvinov reporter

    Just added a routine that computes the encoded length for regular as well as for URL-safe encoding and wired it into the original code (commit f1d03e6). The URL-safe encoding works now, and the original Mig encoding alg is preserved :)

    The next task is to modify decoding to support both modes.

  5. Vladimir Dzhuvinov reporter

    The alternative migbase64 codec is fully integrated now and the commons codec dependency is removed, see release 2.24.

  6. Log in to comment