Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
io  
#1 Posted : Saturday, July 08, 2006 6:59:24 AM(UTC)
io

Rank: Member

Groups: Member
Joined: 6/25/2006(UTC)
Posts: 20

I use
iu.addParam("HashAlgorithm", "MD5");

and got 4 different results on server-side by PHP:
Code:
HashCodeMD5_1                     opHHTfJ8Rx9RJDtrVIqIqw==
base64_decode(HashCodeMD5_1)      ¢‘ÇMò|G.Q$;kTŠˆ«
base64_encode(HashCodeMD5_1)      b3BISFRmSjhSeDlSSkR0clZJcUlxdz09
md5_file(original file)           a291c74df27c471f51243b6b548a88ab


its not a mistake, it is base64_encode() function gives the md5-like string

v.3.5 and v.4 are of the same behavour

what is wrong?
thank you

Edited by user Wednesday, December 19, 2007 4:04:07 PM(UTC)  | Reason: Not specified

Fedor  
#2 Posted : Saturday, July 08, 2006 11:18:30 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,537

Thanks: 4 times
Was thanked: 56 time(s) in 55 post(s)
Please see Robust Upload sample in evaluation package.

Here is short code snippet how to use MD5 hash in PHP:

Code:
$postedMD5Hash = $_POST ["HashCodeMD5_1"];

//Compute MD5 hash. Since Image Uploader sends the hash value encoded with Base 64 algorithm
//the result should be also encoded wi	th Base 64.
$actualMD5Hash = base64_encode(pack("H*",md5_file($_FILES["SourceFile_1"]['tmp_name'])));

//If the result differs from the uploaded one, the upload should be interpreted as corrupted.
if ($postedMD5Hash != $actualMD5Hash)
{
	header("HTTP/1.0 400 Bad Request");
	return;
}
Best regards,
Fedor Skvortsov
io  
#3 Posted : Saturday, July 08, 2006 6:48:15 PM(UTC)
io

Rank: Member

Groups: Member
Joined: 6/25/2006(UTC)
Posts: 20

Thank You, it works.

md5 hash commonly means 32-character hexadecimal number format.
IU hash return raw binary format.
Thus it may be useful to mark this somehow in the HashAlgorithm Property page.

In order to keep the integrity of datdabase i use backward action:
Code:
$md5_arr=unpack("H*",base64_decode($_POST["HashCodeMD5_1"]));
$md5=$md5_arr['1'];

Edited by user Wednesday, December 19, 2007 4:04:31 PM(UTC)  | Reason: Not specified

Fedor  
#4 Posted : Sunday, July 09, 2006 12:48:01 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,537

Thanks: 4 times
Was thanked: 56 time(s) in 55 post(s)
In Image Uploader reference we have mentioned that generated hash value is encoded with base64 encoding. We have design it such way in order to simplify the hash value validation on the most of server platforms (PHP, ASP.NET, Ruby, Python and so on).

Edited by user Tuesday, February 26, 2008 2:14:10 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
io  
#5 Posted : Sunday, July 09, 2006 7:28:24 AM(UTC)
io

Rank: Member

Groups: Member
Joined: 6/25/2006(UTC)
Posts: 20

The right code should be like the following:
Code:
$md5_arr=unpack("H*",base64_decode($_POST["HashCodeMD5_1"]));
$md5=substr($md5_arr['1'],0,-1);

Edited by user Wednesday, December 19, 2007 4:04:43 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.