Jump to content


Photo

md5 and base64 encoding


  • Please log in to reply
9 replies to this topic

#1 grenouille

grenouille
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 October 2006 - 11:41 AM

hi,

i am using an open source (java) filemanager on one of my websites. user data is stored in an xml-file.
when a visitor uses the filemanager itself to register, the password is first md5 encrypted and after that base64 encoded (according to the developer).
now i want to write my own register-form for this filemanager. so i take the password value, md5() and base64_encode() it, but it gives NOT the saùme result as when the filemanager itself encrypts.

f.i password= 19721972  ==> filemanager result = NREVYMjLF45+vX9VM9KAxg==
but : $password=19721972, md5($password) ==> 35111560c8cb178e7ebd7f5533d280c6
  and then base64_encode($password) ==> MzUxMTE1NjBjOGNiMTc4ZTdlYmQ3ZjU1MzNkMjgwYzY=

anyone any idea what may cause this difference? the developer told me he used the Java MessageDigest class
to md5 encrypt.

If you know the answer, please do not get to technical (if possible)  :)

thnx in advance.




#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 11:47 AM

I found your problem.


You had
$password=19721972;
md5($password);
base64_encode($password);

echo $password;

What you want is this
$password = 19721972;
$password = md5($password);
$password = base64_encode($password);

echo $password;

SA PHP Archives - www.phparchives.za.org

#3 grenouille

grenouille
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 October 2006 - 11:52 AM

okay, my explanation was a bit confusing but that is exactly what i did.

<?
$str = 19721972;
$str = md5($str);
$str = base64_encode($str);
echo $str;
?>


#4 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 11:55 AM

Sorry... my bad

Your developer uses raw md5 output...

this fixes it

$password = 19721972;
$password = md5($password, true);
$password = base64_encode($password);

SA PHP Archives - www.phparchives.za.org

#5 grenouille

grenouille
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 October 2006 - 11:58 AM

hm, now i get the following error

Warning: Wrong parameter count for md5() in ...



#6 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 12:10 PM

http://www.php.net/md5

Note:  The optional raw_output parameter was added in PHP 5.0.0 and defaults to FALSE

You must have an older version of PHP running.

SA PHP Archives - www.phparchives.za.org

#7 grenouille

grenouille
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 October 2006 - 12:11 PM

php version is 4.2.2
could this be the cause of raw output failure?

#8 grenouille

grenouille
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 October 2006 - 12:12 PM

okay thnx. i'll upgrade first, then i'll annoy you again with my questions :)

#9 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 12:13 PM

I found a solution:

$password = 19721972;
//$password = md5($password, true);
$password = pack("H*", md5($password));
$password = base64_encode($password);

echo $password;

SA PHP Archives - www.phparchives.za.org

#10 grenouille

grenouille
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 October 2006 - 12:16 PM

yep! that's it!

thnx a lot.

grtz




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users