[racket] string->bytes/locale on an HMAC-SHA1 hash returns error

From: Ray Racine (ray.racine at gmail.com)
Date: Mon May 14 08:19:53 EDT 2012

I have a 100% Racket impl of hmac-sha1 here.  Good enough for signing
smaller sized data such as API calls:

https://github.com/RayRacine/racketlib/blob/master/crypto/hmac.rkt


On Mon, May 14, 2012 at 5:27 AM, Shawn Smith <shawn.p.smith at gmail.com>wrote:

> Hi Norman,
>
> Thanks, that looks great.  I'll give it a shot.
>
> Shawn
>
>
> On Mon, May 14, 2012 at 2:23 AM, Norman Gray <norman at astro.gla.ac.uk>wrote:
>
>>
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120514/84fcc2ed/attachment.html>

Posted on the users mailing list.