Solved

base64_decode returns binary data

Posted on 2006-06-10
6
386 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 38
Wordpress Taxonomy 2 28
Insert values are dynamic 11 41
How can I implement a "Select All" with this configuration...? 6 41
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 how to create an extensible mechanism for linked drop downs.
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 dynamically set the form action using jQuery.

773 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