You are here: HMAC-SHA1 ARGG!!!!! « PHP Programming Language « IT news, forums, messages
HMAC-SHA1 ARGG!!!!!

Posted by cbmeeks on 04/10/07 00:59

ok, here is my problem (PHP newbie here). I have a test webpage that
contains the following code:

[hmac-sha1.php]
<?php
//Calculate HMAC-SHA1 according to RFC2104
// http://www.ietf.org/rfc/rfc2104.txt

function hmacsha1($key,$data) {
$blocksize=64;
$hashfunc='sha1';
if (strlen($key)>$blocksize)
$key=pack('H*', $hashfunc($key));
$key=str_pad($key,$blocksize,chr(0x00));
$ipad=str_repeat(chr(0x36),$blocksize);
$opad=str_repeat(chr(0x5c),$blocksize);
$hmac = pack('H*',$hashfunc(($key^$opad).pack('H*',$hashfunc(($key^
$ipad).$data))));
return base64_encode($hmac);
}
?>


I have another test page that contains:

[test.php]
<?php

require_once("hmac-sha1.php");

$r = $_POST["data"];

echo $r;
echo "\n\n";
echo hmacsha1("OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV",$r);


echo "\n\n\n";
echo hmacsha1("OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV","PUT
\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005
18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/
quotes/nelson");


?>


Now, I have a C# application that POST's data to the second page. It
posts to the "data" variable. The value I post is that strange
looking "PUT\nc...." you see.
Looking at the second page, when I "echo $r" I get exactly what I
posted. But when I "echo hmacsha1" and use the $r variable, I get
something completely different than when I use the hard-coded value.

I hope that makes sense.

Any clues as to why the $r returns a different hash than the hard-
coded method? Even though $r contains the EXACT same copy? I've
checked it byte-per-byte.

I suspect some kind of encoding problem or something.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация