mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add hmac_md5
add hmac_md5
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user