Solved

base64_decode returns binary data

Posted on 2006-06-10
6
384 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 count occurrences of each item in an array.

910 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

21 Experts available now in Live!

Get 1:1 Help Now