Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 583
Alex Florescu Avatar asked Jul 28 '13 19:07

Alex Florescu


People also ask

How do I check if a string is Base64 encoded?

In base64 encoding, the character set is [A-Z, a-z, 0-9, and + /] . If the rest length is less than 4, the string is padded with '=' characters. ^([A-Za-z0-9+/]{4})* means the string starts with 0 or more base64 groups.

What is Base64 encoding and decoding in Java?

Basic Encoding and DecodingIt uses the Base64 alphabet specified by Java in RFC 4648 and RFC 2045 for encoding and decoding operations. The encoder does not add any line separator character. The decoder rejects data that contains characters outside the base64 alphabet.

How do I get Base64 encoded strings?

In JavaScript there are two functions respectively for decoding and encoding Base64 strings: btoa() : creates a Base64-encoded ASCII string from a "string" of binary data ("btoa" should be read as "binary to ASCII"). atob() : decodes a Base64-encoded string("atob" should be read as "ASCII to binary").


1 Answers

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.

like image 144
Alex Florescu Avatar answered Sep 17 '22 12:09

Alex Florescu