Forum Moderators: coopster

Message Too Old, No Replies

Trimming base64 encoded string

removing the equal sign(s)

         

ag_47

4:36 am on Mar 21, 2009 (gmt 0)

10+ Year Member



After a few tries, this seems to be safe. Just want to double-check to make sure no problems arise later on.

eg.
base64_encode('This is an encoded string') ==> 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw='

and
base64_deocde('VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw') ==> 'This is an encoded string'

So removing the '='s from the end is no prob? (they are there from 'completion' anyway right?)

eeek

4:47 am on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So removing the '='s from the end is no prob?

Why would you do that? They do actually mean something.

ag_47

4:55 am on Mar 21, 2009 (gmt 0)

10+ Year Member



Why would you do that?

To make URL safe (I know I could replace them with a different character, but having one/two symbols at the end kind of gives base64 away..)

blang

7:33 am on Mar 21, 2009 (gmt 0)

10+ Year Member



Have you read anything about base64 [en.wikipedia.org]?

ag_47

9:07 am on Mar 21, 2009 (gmt 0)

10+ Year Member



Yes, I have.

After trying several examples it seemed removing = doesn't make a difference when decoding (at least in PHP) - but I decided to double-check here anyway.
Since = is used for padding (ie. indicate the addition of 0s at the end), the base64_decode function in PHP seems to take care of this if '=' are omitted.