Is there any difference between Apache's Base64.encodeBase64 and Android's Base64.encode with Base64.Default flag?

Alex Florescu picture Alex Florescu · Jul 28, 2013 · Viewed 16k times · Source

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?

Answer

Alex Florescu picture Alex Florescu · Jul 28, 2013

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.