Solved

PHP: Characters and Order for base64-encode()

Posted on 2010-11-09
3
306 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 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