Update: Found out I can do this:<div><br></div><div><a href="https://github.com/plt/racket/wiki/Artifacts">https://github.com/plt/racket/wiki/Artifacts</a></div><div><br></div><div><pre style="margin-top:15px;margin-bottom:15px;padding-top:6px;padding-right:10px;padding-bottom:6px;padding-left:10px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-style:initial;border-color:initial;font:inherit;font-family:'Bitstream Vera Sans Mono',Courier,monospace;line-height:19px;background-color:rgb(248,248,248);border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204,204,204);border-right-color:rgb(204,204,204);border-bottom-color:rgb(204,204,204);border-left-color:rgb(204,204,204);overflow-x:auto;overflow-y:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)">
<code style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;border-style:initial;font:inherit;font-family:'Bitstream Vera Sans Mono',Courier,monospace;line-height:normal;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border-color:initial;background-image:initial;border-width:initial">(parameterize ([current-input-port (open-input-string "We are Spinal Tap!")])
(with-output-to-string (λ _ (system* (build-path "c:" "openssl-win32" "bin" "openssl.exe")
"dgst"
"-sha1"
"-hex"
"-hmac"
#"mysecretkey"))))</code></pre><br><div class="gmail_quote">On Mon, May 14, 2012 at 1:12 AM, Shawn Smith <span dir="ltr"><<a href="mailto:shawn.p.smith@gmail.com" target="_blank">shawn.p.smith@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><span>I guess I've tracked the problem down to the fact that the Racket hash is not a digest.</span><div>
<br></div><div>I don't really know what that means.</div><div><br></div><div>If I do:</div>
<div><br></div><div>echo -n "foo" | openssl dgst -sha1 -hmac "privatekey"</div><div><br></div><div>I get what I'm looking for, a 40 character hex hash: </div><div><br>
</div><div>6d1198d3c8770f2409c6b73ed11af9d2076e4588</div><div><br></div><div>I'm not sure how to get Racket to do this as well. Does anyone know?</div><br></div><div class="gmail_quote"><div class="im">On Sun, May 13, 2012 at 9:32 PM, Veer Singh <span dir="ltr"><<a href="mailto:veer.chah@gmail.com" target="_blank">veer.chah@gmail.com</a>></span> wrote:<br>
</div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In racket you are applying function "base64-encode" and in python you are not.<br>
<br>
Sorry if I didn't get your question.<br>
<br>
Veer.<br>
<div><div><br>
On Mon, May 14, 2012 at 9:38 AM, Shawn Smith <<a href="mailto:shawn.p.smith@gmail.com" target="_blank">shawn.p.smith@gmail.com</a>> wrote:<br>
> Having issues with mailing list. Trying again:<br>
><br>
> I've gotten a bit of help in #racket on freenode so far, but I'm still<br>
> facing a problem with this.<br>
><br>
> In Racket, I expect that this will get me a SHA1 hash (as bytes) of a<br>
> string, using a key:<br>
><br>
> (require web-server/stuffers/hmac-sha1<br>
> net/base64)<br>
><br>
> (define (str-to-hash private-key str)<br>
> (base64-encode (HMAC-SHA1 (string->bytes/utf-8 private-key)<br>
> (string->bytes/utf-8 str))))<br>
><br>
> And let's convert the bytes to a string of hex:<br>
><br>
> (apply string-append (map (lambda (x) (number->string x 16)) (bytes->list<br>
> (str-to-hash "foo" "bar"))))<br>
><br>
> This gives me:<br>
><br>
> "527254735747455846553273314a316d546c316a2f63694f2b31453dda"<br>
><br>
> In Python, doing what I assume to be the same thing:<br>
><br>
> import hmac<br>
> from hashlib import sha1<br>
><br>
> hmac.new('foo', 'bar', sha1).hexdigest()<br>
><br>
> Returns something completely different:<br>
><br>
> '46b4ec586117154dacd49d664e5d63fdc88efb51'<br>
><br>
> Does anyone have any idea what's going on here?<br>
><br>
> On Sun, May 13, 2012 at 9:01 PM, Shawn Smith <<a href="mailto:shawn.p.smith@gmail.com" target="_blank">shawn.p.smith@gmail.com</a>><br>
> wrote:<br>
>><br>
>> I've gotten a bit of help in #racket on freenode so far, but I'm still<br>
>> facing a problem with this.<br>
>><br>
>> In Racket, I expect that this will get me a SHA1 hash (as bytes) of a<br>
>> string, using a key:<br>
>><br>
>> (require web-server/stuffers/hmac-sha1<br>
>> net/base64)<br>
>><br>
>> (define (str-to-hash private-key str)<br>
>> (base64-encode (HMAC-SHA1 (string->bytes/utf-8 private-key)<br>
>> (string->bytes/utf-8<br>
>> str))))<br>
>><br>
>> And let's convert the bytes to a string of hex:<br>
>><br>
>> (apply string-append (map (lambda (x) (number->string x 16)) (bytes->list<br>
>> (str-to-hash "foo" "bar"))))<br>
>><br>
>> This gives me:<br>
>><br>
>> "527254735747455846553273314a316d546c316a2f63694f2b31453dda"<br>
>><br>
>> In Python, doing what I assume to be the same thing:<br>
>><br>
>> import hmac<br>
>> from hashlib import sha1<br>
>><br>
>> hmac.new('foo', 'bar', sha1).hexdigest()<br>
>><br>
>> Returns something completely different:<br>
>><br>
>> '46b4ec586117154dacd49d664e5d63fdc88efb51'<br>
>><br>
>> Does anyone have any idea what's going on here?<br>
>><br>
>> Shawn<br>
>><br>
>> On Sun, May 13, 2012 at 7:18 PM, Shawn Smith <<a href="mailto:shawn.p.smith@gmail.com" target="_blank">shawn.p.smith@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> I'm trying to generate a SHA1 hash using a private key and a given<br>
>>> string, like so:<br>
>>><br>
>>> (define a-hash (HMAC-SHA1 (string->bytes/locale "foo")<br>
>>> (string->bytes/locale "bar")))<br>
>>><br>
>>> This returns bytes, but when I try to turn those bytes into a string<br>
>>> with:<br>
>>><br>
>>> (bytes->string/locale a-hash)<br>
>>><br>
>>> I get:<br>
>>><br>
>>> bytes->string/locale: string is not a well-formed UTF-8 encoding:<br>
>>> #"F\264\354Xa\27\25M\254\324\235fN]c\375\310\216\373Q"<br>
>>><br>
>>> As I have no clue how to diagnose this, I'd appreciate any suggestions or<br>
>>> help.<br>
>>><br>
>>> Thanks,<br>
>>> Shawn<br>
>><br>
>><br>
><br>
><br>
</div></div>> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
</blockquote></div></div></div><br>
</blockquote></div><br></div>