29

Sample A (using org.apache.commons.codec.binary.Base64):

Base64.encodeBase64("foobar".getBytes()); 

Sample B (using android.util.Base64):

Base64.encode("foobar".getBytes(), Base64.DEFAULT); 

Do these produce the same string?

1 Answer 1

82

No, the difference is that with the default settings, Android's Base64 includes line terminators. To obtain the same result as with the Apache encoding, use Base64.NO_WRAP.

1
  • 2
    Does the same hold for android.util.Base64.decode() ? Dec 2, 2016 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.