Solved

PHP: Characters and Order for base64-encode()

Posted on 2010-11-09
3
296 Views
Last Modified: 2012-05-10
Wikipedia lists the Base64 index (in order): as this:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

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.
0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34093037
0
 
LVL 16

Author Comment

by:hankknight
ID: 34093201
That does NOT contain a complete ordered index as used by used by PHP.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34093763
It may be as close as we can get.  From the PHP man pages:

"base64_encode — Encodes data with MIME base64"
http://us2.php.net/manual/en/function.base64-encode.php

Some research:
http://lmgtfy.com?q=MIME+base64

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:
http://en.wikipedia.org/wiki/Base64

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.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question