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?
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.
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.
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").
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With