Forum OpenACS Development: Re: ns_hmac and byte array
actually, the code seems to make the right things. With a little debugging in naviserver activated, one can see that the binary string is correctly handled as a bytearray:
% set b [binary format H* "abcd1234"] «Í4 % set h [ns_hmac string -digest SHA512 $b "This is a test"] hmac key (len 4): ab cd 12 34 7d783715c6aedd1e9d0ee5f310da502a0540048a525d64964a9bb7e7b8c6782cacbfba8a2870cd7c9892a99da89404ca47f219dcb50c7ae5fb454704734473b8
Per default, the ouput encoding is hex, but one can specify as well base64url, base64, or binary. What result did you expect?
When I run this code on my Naviserver it returns a different result.
I am not sure if this is a result of a different library I have or some Naviserver encoding setting perhaps. Very curious.
set b [binary format H* "abcd1234"]
set h [ns_hmac string -digest SHA512 $b "This is a test"]
b results in the same value «Í4
but h contains a different result
Do you see a different result, or do get the same result, but expecting a different one?
I believe the result your code returns is the correct response.
My code is returning a different value, but it looks like its the same. I'll try adding the debugging code.
I checked and I am running Naviserver 4.99.16.
I compiled Naviserver 4.99.17 with Tcl 8.5.19 to see if the issue resolved itself, and I am not getting the same result as your example.
It does appear the Naviserver version affected the results, and not the Tcl version.
all the best