1

PHP code:

 function compute_signature($key, $hash_string)
    {
        $digest = hash_hmac("sha1", $hash_string, $key, true);
        return base64_encode($digest);
    }

Ruby Code:

    digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString)
return Base64.encode64(digest.to_s()).chomp()

Could this be a charset issue? I found this: C# SHA-1 vs. PHP SHA-1...Different Results?

If so how could I fix? Note I must make PHP match Rubys results, the reverse would not help in this situation.

Community
  • 1
  • 1
stormist
  • 5,709
  • 12
  • 46
  • 65

1 Answers1

1

In the Ruby version you have a base64-encoded key; in PHP you are using the $key directly as a binary key. Could that be the issue?

(As for charsets, well, do you have any non-ASCII in there? What's a typical $hash_string?)

bobince
  • 528,062
  • 107
  • 651
  • 834
  • Should have clarified on the $key, when I pass it on the php side its already base64 decoded. A typical hashstring is alphanumeric. (web request headers) – stormist Dec 10 '09 at 17:53
  • hmm, you'd think that'd work then... unless it contains non-matching newlines, perhaps? How about an example value/hash? Would at least enable us to see whether it was the PHP or Ruby version that was “wrong”... – bobince Dec 10 '09 at 19:48