Solved

PHP: Characters and Order for base64-encode()

Posted on 2010-11-09
3
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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 110

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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
How Close unsubmited attempts 10 46
PHP Curl Problem 10 41
How do I remove "" from json_encode 5 22
Set a time limit on Wordpress Cookie function. 3 14
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to dynamically set the form action using jQuery.

733 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