Solved

base64_decode returns binary data

Posted on 2006-06-10
6
382 Views
Last Modified: 2012-08-14
the base64_decode() returns data in binary!

ive tried to display the output from base64_decode($handshake) and i get binary??

is there someother function that can convert the decoded data in readable data so i can compare it in my code below?

<?php
$handshake = '';
$handshake = trim($_GET['handshake']);

if("xyz" == base64_decode($handshake))
      echo "Handshake OK";
else
      echo "HACKING ATTEMPT";
?>
0
Comment
Question by:ellandrd
  • 4
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 16876868
Is it serialized perhaps? Normally the function returns the decoded string, so that's weird...
What is it you encode...
Can you show us the whole cycle? SO, both the encoding and decoding part?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16877084
OK, example:

<?php
$str = 'secret';
$encoded_str = base64_encode($str);
if("secret" == base64_decode($encoded_str))
     echo "OK";
else
     echo "HACKING ATTEMPT";
?>

will fail as base64_decode() return binary data.  How can i decode a string encrpyted by base64?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16877106
see another example:

<?php
$encoded_str = "KHvCoxP73EqvnVaCubzwUQ==";
echo "<p>".$encoded_str."</p>";
$decoded_str = base64_decode($encoded_str);
echo "<p>".$decoded_str."</p>";
?>

output:

KHvCoxP73EqvnVaCubzwUQ==

({£ûÜJ¯V‚¹¼ðQ

The $encoded_str value is a string encoded using a base64 algorithm sent in the URL....

 
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Author Comment

by:ellandrd
ID: 16877141
fixed!
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 16877286
Well done, can you tell us how, so people with the same problem can use your solution...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16877853
i use md5 hashing instead.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now