diff --git a/lualib/md5.lua b/lualib/md5.lua index 26f5cfa6..90e28739 100644 --- a/lualib/md5.lua +++ b/lualib/md5.lua @@ -15,4 +15,24 @@ function core.sumhexa (k) end)) end -return core \ No newline at end of file +local function get_ipad(c) + return string.char(c:byte() ~ 0x36) +end + +local function get_opad(c) + return string.char(c:byte() ~ 0x5c) +end + +function core.hmacmd5(data,key) + if #key>64 then + key=core.sum(key) + key=key:sub(1,16) + end + local ipad_s=key:gsub(".", get_ipad)..string.rep("6",64-#key) + local opad_s=key:gsub(".", get_opad)..string.rep("\\",64-#key) + local istr=core.sum(ipad_s..data) + local ostr=core.sumhexa(opad_s..istr) + return ostr +end + +return core