Skip to content

Commit

Permalink
add hmac_md5
Browse files Browse the repository at this point in the history
add hmac_md5
  • Loading branch information
wangyi0226 committed Oct 26, 2015
1 parent 26cbebf commit f5740e0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lualib/md5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,22 @@ function core.sumhexa (k)
end))
end

return core
function core.hmac_md5(data,key)
if #key>64 then
key=core.sum(key)
key=string.sub(key,1,16)
end

local b=table.pack(string.byte(key,1,#key))
local ipad_s=""
local opad_s=""
for i=1,64 do
ipad_s=ipad_s..string.char((b[i] or 0)~0x36)
opad_s=opad_s..string.char((b[i] or 0)~0x5c)
end
local istr=core.sum(ipad_s..data)
local ostr=core.sumhexa(opad_s..istr)
return ostr
end

return core

0 comments on commit f5740e0

Please sign in to comment.