jkeys089 / lua-resty-hmac

HMAC functions for ngx_lua and LuaJIT
160 stars 99 forks source link

how to use sha256 without key #30

Closed C4o closed 3 years ago

C4o commented 3 years ago

I set the KEY to "", but the result is not right...How can i do..

jkeys089 commented 3 years ago

@C4o using an empty key should work fine. E.g.

ngx.say(hmac:new("", hmac.ALGOS.SHA256):final("hello, world!", true))
  -- output: "2f0dc4b94797ef8e149c247a6eb13df7a8f4aaf8eea19dfb548f7f80d25cef0c"
jkeys089 commented 3 years ago

@C4o in your example you've computed the sha-256 hash. This lib computes HMAC. The comparable Go code would look like https://play.golang.org/p/mmzDteED9CL.

C4o commented 3 years ago

sorry...