Jump to content

Archived

This topic is now archived and is closed to further replies.

grenouille

md5 and base64 encoding

Recommended Posts

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.


Share this post


Link to post
Share on other sites
I found your problem.


You had
[code]
$password=19721972;
md5($password);
base64_encode($password);

echo $password;
[/code]

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

echo $password;
[/code]

Share this post


Link to post
Share on other sites
okay, my explanation was a bit confusing but that is exactly what i did.

[code]
<?
$str = 19721972;
$str = md5($str);
$str = base64_encode($str);
echo $str;
?>
[/code]

Share this post


Link to post
Share on other sites
Sorry... my bad

Your developer uses raw md5 output...

this fixes it

[code]
$password = 19721972;
$password = md5($password, true);
$password = base64_encode($password);
[/code]

Share this post


Link to post
Share on other sites
[url=http://www.php.net/md5]http://www.php.net/md5[/url]

[code]Note:  The optional raw_output parameter was added in PHP 5.0.0 and defaults to FALSE[/code]

You must have an older version of PHP running.

Share this post


Link to post
Share on other sites
I found a solution:

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

echo $password;
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.