|
|
Rank: Member Groups: Member
Joined: 6/25/2006 Posts: 19 Points: 6 Location: Kiev, Ukraine
|
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
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
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
|
|
Rank: Member Groups: Member
Joined: 6/25/2006 Posts: 19 Points: 6 Location: Kiev, Ukraine
|
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'];
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
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).
Best regards, Fedor Skvortsov
|
|
Rank: Member Groups: Member
Joined: 6/25/2006 Posts: 19 Points: 6 Location: Kiev, Ukraine
|
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);
|
|
|
Guest |