• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

PHP: Characters and Order for base64-encode()

Wikipedia lists the Base64 index (in order): as this:

Open in new window

However that does NOT seem to be the the index used by PHP.  What is the ordered Base64 index for PHP?

Oddly, the PHP manual does not seem to list this information.
  • 2
1 Solution
Ray PaseurCommented:
hankknightAuthor Commented:
That does NOT contain a complete ordered index as used by used by PHP.
Ray PaseurCommented:
It may be as close as we can get.  From the PHP man pages:

"base64_encode — Encodes data with MIME base64"

Some research:

The Base64 encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented per printable character.  This amounts to the required 64 characters and a pad character.

MIME's Base64 implementation uses A–Z, a–z, and 0–9 for the first 62 values.  I would expect + and / to be the last two characters.  Other variations, usually derived from Base64, share this property but may differ in the last two symbols (UTF-7).  An additional pad character , usually the = is used to force the encoded output into an integer multiple of 4 characters.  If you test with different strings, you will quickly realize that characters will be encoded differently depending on their position in the string.

An index table, and a table of variants is given here:

So I guess the question is, "Why do you think that PHP does not use the index that PHP says it uses?"  Is there a test case that you can show us to demonstrate what PHP is doing wrong?  I have probably sent over 100,000 base64 encoded strings to numerous different programs, and I've never gotten a complaint that it did not decode correctly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now