note 78549 added to function.md5
| From: | SantaCruzskelly at osu1 dot php dot net | Date: | Wed, 17 Oct 2007 03:18:48 +0000 |
| Subject: | note 78549 added to function.md5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131442@lists.php.net to get a copy of this message | ||
Re: public at kreinacke dot com
It has long been a point of frustration to me that md5() functions don't produce the same
results as the *nix md5sum program. Reading your comments about the incongruity today pushed me over
the edge to finally understand why. The answer, I believe I have found, is that md5sum includes an
extra newline as the termination of the file content. ugh.
In response I have produced the following function that, at least on my server, produces a result
matching the output of md5sum on the command line:
function md5sum($str) { return(md5($str . "\n")); }
Yes, that easy.
My results from typing the string "apples and oranges" into a PHP script using that
function and the same string entered into a file on disk using md5sum on the command line to pull it
return:
6c1111418017a050006eee9f2bdda2bf
Your
echo -n "apples and oranges | md5sum method (which suppresses that newline I
refer to!) and PHP's normal md5() function also return the same result as one another as you
described, but those are string based operations. My solution is a function that reproduces the
result of md5sum's assessment of on-disk data based on the contents of the file being in a
string, something that's critical to my application.
----
Server IP: 208.69.120.35
Probable Submitter: 69.225.165.46
----
Manual Page -- http://www.php.net/manual/en/function.md5.php
Edit -- https://master.php.net/note/edit/78549
Del: integrated -- https://master.php.net/note/delete/78549/integrated
Del: useless -- https://master.php.net/note/delete/78549/useless
Del: bad code -- https://master.php.net/note/delete/78549/bad+code
Del: spam -- https://master.php.net/note/delete/78549/spam
Del: non-english -- https://master.php.net/note/delete/78549/non-english
Del: in docs -- https://master.php.net/note/delete/78549/in+docs
Del: other reasons-- https://master.php.net/note/delete/78549
Reject -- https://master.php.net/note/reject/78549
Search -- https://master.php.net/manage/user-notes.php