46

I'm using Base64 encoding for encoding user id field in Java.

String abc = new String(Base64.encodeBase64("Actualuseridfield"));

I want to know whether the string abc above will contain the character " , : or not?

When the Base64 encoded string is returned in abc, will it ever contain below characters?

" <double quote> 
, <comma> 
: <colon>
2
  • 16
    Base64 is NOT encryption. It is a method of encoding binary data so it can be represented using only printable characters. It is trivially reversible. If you are expecting the data to be secure you will be disappointed. Commented May 21, 2013 at 23:32
  • 2
    I wouldn't say you won't find any comma in a base64 encoded (in general) perhaps for your case, that library won't use any other variation, but you can find variation of base64 that do contain comma in it according to en.wikipedia.org/wiki/Base64#Variants_summary_table "Modified Base64 encoding for IMAP mailbox names (RFC 3501)" Commented Mar 8, 2017 at 8:37

3 Answers 3

51

You will not see any commas, colons, or double quotes in a Base64 encoded string. You will see equals signs since they're used to pad the ending content.

Sign up to request clarification or add additional context in comments.

3 Comments

= sign is not always there
padding = will only exist, if the length of the result doesn't exactly match the final block length. Blocks are 24bit length - so you'll usually see 0 - 3 paddings
Curious if single quote will be there ?
30

If you have a proper encoder for Base64, you will not see special characters except:

[A-Z][a-z][0-9][+/] and the padding char '=' at the end to indicate the number of zero fill bytes

There is another Base64 character set available which replaces [+/] by [_-] making the encoding URL-safe.

Nevertheless the specification allows to include any other character. Often the Base64 encoded data contains a line feed '\n' every 76 characters. Any character except the ones mentioned above has to be removed during decoding. The padding characters indicate the number of zero bytes appended to apply to n*4 output characters.

Comments

5

transforming "weird" and non printable characters is kind of the whole point of base64, so no, you wont see those. more info here http://email.about.com/cs/standards/a/base64_encoding.htm

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.