Base64 Valid Character Set


I found this on a forum post, and just wanted to verify that this information is correct:

for base64 the valid charset is:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx yz0123456789+/
the = is used as filler for the last bytes, as the length must be mulitple
of 3

(via thescripts.com/forum)

The charset looks reasonable, but must the length be a multiple of 3? (Seems like a multiple of 4 would make more sense.)

Comments very much appreciated!

5 Comments

  1. Sinfocol says:

    I was searching about some features of the base64 encoding when I looked your page, I think that you already know about the “=” character on the encoding, well, I want to publish here, the “=” character “is used to signify a special processing functions”, you can look the definition in the RFC: http://www.faqs.org/rfcs/rfc4648.html
    And yes, the length of the text must be 3, because 24 bits (3 bytes) are treated as 4 concatened 6-bit groups, so a padding is used in a text where its length is not multiple of 3.
    b64(‘a’) = “YQ==”
    b64(“ab”) = “YWI=”
    b64(“abc”) = “YWJj”
    b64(“abcd”) = “YWJjZA==”

  2. Thank you. simple and straight forward
    i was looking for a safe delimiter between two or more base64 encoded strings
    i think i’ll go with | πŸ™‚

  3. When used in JSON comunications, JSON changes “+” to “”. I needed to change every “+” to “_” in order to be able to use Base64 in JSON

  4. Jeannine Lee says:

    Interesting, I always wondered about the mystery =’s at the end of my encoded strings, (but not enough to google it πŸ˜‰

    I, too, came to this site while looking for a nice delimiter. I didn’t think | was valid in the character set, thanks for confirmation.

  5. amandalishus says:

    Is there supposed to be a ‘\b’ (blank space) between the ‘x’ and the ‘y’ in your string of valid characters? I noticed it when I went to paste it into my code (“Plagiarism is the sincerest form of flattery.” πŸ™‚ ), but I kind of doubt it was supposed to be there. Might be worth editing though… you’ll probably save some poor sucker who was paying less attention than me from hours of debugging a ridiculous little bug based on that character πŸ˜‰

Leave a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s