Shawn, hello.

On 2012 May 14, at 09:12, Shawn Smith wrote:

> I guess I've tracked the problem down to the fact that the Racket hash is
> not a digest.

I think it is, but the problem is that you're not displaying the resulting byte 
string correctly.

> echo -n "foo" | openssl dgst -sha1 -hmac "privatekey"
> 
> I get what I'm looking for, a 40 character hex hash:
> 
> 6d1198d3c8770f2409c6b73ed11af9d2076e4588
> 
> I'm not sure how to get Racket to do this as well.  Does anyone know?

(require web-server/stuffers/hmac-sha1
         file/sha1) ; or openssl/sha1

(bytes->hex-string (HMAC-SHA1 #"privatekey" #"foo"))

=> "6d1198d3c8770f2409c6b73ed11af9d2076e4588"

HMAC-SHA1 produces the result as a byte string (which is different from a 
string).  Base-64 encoding writes out that string of bytes in a form which can 
be safely mailed -- that's not what you want.

Instead, bytes->hex-string formats each byte in the string as a two-digit hex 
number, resulting in a string.

All the best,

Norman


-- 
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK


____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to