Re: hash_hmac: Encoding with two different results problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 24, 2008 at 1:21 AM, Nathan Nobbe <quickshiftin@xxxxxxxxx>wrote:

> On Thu, Jul 24, 2008 at 12:50 AM, Leon du Plessis <leon@xxxxxxxxxx> wrote:
>
>> hi,
>> I hope this is the right group for this type of problem:
>>
>> I am using hash_hmac to provide me with a sha1 encoded hash string. The
>> problem is as follows:
>>
>> $hash = hash_hmac('sha1',
>>
>> '030B6A05696E657400C54601C60001550187360603773500018707060373796E63000187340603687474703A2F2F7777772E73796E632E636F6D2F73796E630001C65901873A06032E2F636F6E7461637473000187070603436F6E74616374732044420001872E0603746578742F782D7663617264000101C6570187310603757365726E616D6500018732060370617373776F72640001010101',
>> '1234');
>>
>> Note: it is important the key to use during encoding id 1234 for this
>> example.
>>
>> Result:
>> eb38ffd597c6d1e01cd24a0e46dff426354510fe
>>
>> Using a hash calculator from slavasoft also yields this result, which
>> indicate the encoding is fine.
>> eb38ffd597c6d1e01cd24a0e46dff426354510fe
>>
>> However, Slavasoft's calculator has an option to provide the string as
>> Text
>> or Hex.
>>
>> Selecting "hex" yields this result:
>> 9f9be99ea5bf5ba009af0a5c12021f420cb27652  ....and this is the string I
>
>
>> need!!!
>>
>> So either hash_hmac function needs a way to let it know the string is of
>> type hex....or the string itself needs to be converted. I have tried some
>> conversions on the string but to no avail.
>> Anyone have any thoughts?
>
>
> gotchu covered ;)
>
> found this on the web:
>
> http://www.pgregg.com/projects/php/code/hexstr.phps
>
> so then,
>
> <?php
>
> function hexstr($hexstr) {
>   $hexstr = str_replace(' ', '', $hexstr);
>   $retstr = pack('H*', $hexstr);
>   return $retstr;
> }
>
> $hash = hash_hmac('sha1', hexstr(
>
> '030B6A05696E657400C54601C60001550187360603773500018707060373796E63000187340603687474703A2F2F7777772E73796E632E636F6D2F73796E630001C65901873A06032E2F636F6E7461637473000187070603436F6E74616374732044420001872E0603746578742F782D7663617264000101C6570187310603757365726E616D6500018732060370617373776F72640001010101'),
> '1234');
>
> echo $hash;
> ?>
>
> produc
>
>
damnit, its late, so im going to take the liberty to post a follow-up
message to finish that last one off;

(the code from the previous post) produces

9f9be99ea5bf5ba009af0a5c12021f420cb27652

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux