在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jkeys089/lua-resty-hmac开源软件地址(OpenSource Url):https://github.com/jkeys089/lua-resty-hmac开源编程语言(OpenSource Language):Perl 57.1%开源软件介绍(OpenSource Introduction):Namelua-resty-hmac - HMAC functions for ngx_lua and LuaJIT Table of ContentsStatusThis library is still under active development and is considered production ready. DescriptionThis library requires an nginx build with OpenSSL, the ngx_lua module, and LuaJIT 2.0. Synopsis # nginx.conf:
lua_package_path "/path/to/lua-resty-hmac/lib/?.lua;;";
server {
location = /test {
content_by_lua_file conf/test.lua;
}
}
-- conf/test.lua:
local hmac = require "resty.hmac"
local hmac_sha1 = hmac:new("secret_key", hmac.ALGOS.SHA1)
if not hmac_sha1 then
ngx.say("failed to create the hmac_sha1 object")
return
end
local ok = hmac_sha1:update("he")
if not ok then
ngx.say("failed to add data")
return
end
ok = hmac_sha1:update("llo")
if not ok then
ngx.say("failed to add data")
return
end
local mac = hmac_sha1:final() -- binary mac
local str = require "resty.string"
ngx.say("hmac_sha1: ", str.to_hex(mac))
-- output: "hmac_sha1: aee4b890b574ea8fa4f6a66aed96c3e590e5925a"
-- dont forget to reset after final!
if not hmac_sha1:reset() then
ngx.say("failed to reset hmac_sha1")
return
end
-- short version
ngx.say("hmac_sha1: ", hmac_sha1:final("world", true))
-- output: "hmac_sha1: 4e9538f1efbe565c522acfb72fce6092ea6b15e0" MethodsTo load this library,
local hmac = require "resty.hmac" new
Creates a new hmac instance. If failed, returns The The update
Updates the MAC calculation to include new data. If failed, returns The final
Finalizes the MAC calculation and returns the final MAC value. If failed, returns The The reset
Resets the internal hmac context so it can be re-used to calculate a new MAC. If failed, returns This MUST be called after Prerequisites
InstallationIt is recommended to use the latest ngx_openresty bundle directly. You'll need to enable LuaJIT when building your ngx_openresty
bundle by passing the Also, You need to configure the lua_package_path directive to add the path of your lua-resty-hmac source tree to ngx_lua's Lua module search path, as in # nginx.conf
http {
lua_package_path "/path/to/lua-resty-hmac/lib/?.lua;;";
...
} and then load the library in Lua: local hmac = require "resty.hmac" Copyright and LicenseThis module is licensed under the BSD license. Copyright (C) 2012-2021, Thought Foundry Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. See Also
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论