#26485 [Asn->Bgs]: sha1 generates a wrong hash
| From: | derick@php.net | Date: | Mon, 01 Dec 2003 12:55:16 +0000 |
| Subject: | #26485 [Asn->Bgs]: sha1 generates a wrong hash | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-51469@lists.php.net to get a copy of this message | ||
ID: 26485
Updated by: derick@php.net
Reported By: dietrich at pegestorf dot de
-Status: Assigned
+Status: Bogus
Bug Type: *General Issues
Operating System: linux
PHP Version: 4.3.4
Assigned To: derick
New Comment:
There is no bug here at all.
The echo test you do is flawed because echo always appends a \n, see
with:
echo -n test | openssl dgst -sha1
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
that that is correct.
Your file also has 5 characters most likely (using VIM?). With really
only 'test' in it it works fine:
derick@kossu:~$ ls -l /tmp/data
-rw-r--r-- 1 derick derick 4 Dec 1 13:53 /tmp/data
derick@kossu:~$ php-4.3dev -r 'echo sha1_file("/tmp/data");';
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
and
derick@kossu:~$ openssl dgst -sha1 /tmp/data
SHA1(/tmp/data)= a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
Previous Comments:
------------------------------------------------------------------------
[2003-12-01 07:50:09] derick@php.net
I'll have a look at fixing this...
------------------------------------------------------------------------
[2003-12-01 07:41:35] dietrich at pegestorf dot de
Description:
------------
I try to generate a sha1 hash with sha1()
$hash = sha1("test");
$hash is calculated wrong to:
"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
I have a file /tmp/data with the word "test" in it (no carriage return
at the end)
$hash = sha1_file("/tmp/data");
$hash is calculated right to:
"4e1243bd22c66e76c2ba9eddc1f91394e57f9f83"
let's go tho the command line and enter:
echo test | openssl dgst -sha1
this generate also "4e1243bd22c66e76c2ba9eddc1f91394e57f9f83"
same than
openssl dgst -sha1 /tmp/data
If I generate the hash over "test\n" with the sha1() the hash is
calculated right to "4e1243bd22c66e76c2ba9eddc1f91394e57f9f83"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26485&edit=1