Nibble
Nibble

Reputation: 101

Wrong HMAC using PHP 5.0.4

I'm trying to enable HMAC Hashing (SHA256) with PHP 5.0.4 and using phpseclib (to my knowledge in this case phpseclib relies on a native PHP spec), the sample code I'm using it's pretty simple:


    include('Crypt/Hash.php');

    $hash = new Crypt_Hash('sha256');
    $hash->setKey('abcdefg');
    echo bin2hex($hash->hash('something'));

it generates an HMAC with this string:

e678e33c727ddf7172d3521cf9c0c2a15b66e03eb96d77795fa4adb338dc24a9

But apparently, this string is invalid because doing the same with this online tools:

http://www.freeformatter.com/hmac-generator.html

http://beautifytools.com/hmac-generator.php

http://www.jetcityorange.com/hmac/

I get this string:

9a43ff294bdfed399e2d5a3d739a4efb7eccc23269b80b3f0d855937d35ae06f

What am I doing wrong?

Note: SHA1 encoding works perfectly.

Thanks in advance.

Upvotes: 0

Views: 527

Answers (1)

Nibble
Nibble

Reputation: 101

It was a problem related to float to int conversions on 32-bit Linux pre-PHP 5.3. Developers of phpseclib fixed the issue on version 1.0.4 & 2.0.4

Upvotes: 1

Related Questions