lua-resty-aes

用于 ngx_lua 和 LuaJIT 的 AES 加密和解密

$ opm get c64bob/lua-resty-aes

lua-resty-aes

用于 ngx_lua 和 LuaJIT 的 AES 加密和解密

描述

该库需要使用 OpenSSL 构建的 nginx,以及 ngx_lua 模块LuaJIT 2.0

概要

        # nginx.conf:
    
        lua_package_path "/path/to/lua-resty-aes/lib/?.lua;;";
    
        server {
            location = /test {
                content_by_lua_file conf/test.lua;
            }
        }
    
        -- conf/test.lua:
        local aes = require "resty.aes"
        local str = require "resty.string"
        local aes_128_cbc_md5 = aes:new("AKeyForAES")
            -- the default cipher is AES 128 CBC with 1 round of MD5
            -- for the key and a nil salt
        local encrypted = aes_128_cbc_md5:encrypt("Secret message!")
        ngx.say("AES 128 CBC (MD5) Encrypted HEX: ", str.to_hex(encrypted))
        ngx.say("AES 128 CBC (MD5) Decrypted: ", aes_128_cbc_md5:decrypt(encrypted))
    
        local aes = require "resty.aes"
        local str = require "resty.string"
        local aes_256_cbc_sha512x5 = aes:new("AKeyForAES-256-CBC",
            "MySalt!!", aes.cipher(256,"cbc"), aes.hash.sha512, 5)
            -- AES 256 CBC with 5 rounds of SHA-512 for the key
            -- and a salt of "MySalt!!"
            -- Note: salt can be either nil or exactly 8 characters long
        local encrypted = aes_256_cbc_sha512x5:encrypt("Really secret message!")
        ngx.say("AES 256 CBC (SHA-512, salted) Encrypted HEX: ", str.to_hex(encrypted))
        ngx.say("AES 256 CBC (SHA-512, salted) Decrypted: ",
            aes_256_cbc_sha512x5:decrypt(encrypted))
    
        local aes = require "resty.aes"
        local str = require "resty.string"
        local aes_128_cbc_with_iv = assert(aes:new("1234567890123456",
            nil, aes.cipher(128,"cbc"), {iv="1234567890123456"}))
            -- AES 128 CBC with IV and no SALT
        local encrypted = aes_128_cbc_with_iv:encrypt("Really secret message!")
        ngx.say("AES 128 CBC (WITH IV) Encrypted HEX: ", str.to_hex(encrypted))
        ngx.say("AES 128 CBC (WITH IV) Decrypted: ",
            aes_128_cbc_with_iv:decrypt(encrypted))

版权和许可

该模块采用 BSD 许可证授权。

版权所有 (C) 2012-2018,由 Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>,OpenResty Inc。

保留所有权利。

在满足以下条件的情况下,允许以源代码和二进制形式重新分发和使用本软件,无论是否修改:

  • 源代码的再分发必须保留上述版权声明、此条件列表和以下免责声明。

  • 二进制形式的再分发必须在随分发提供的文档和/或其他材料中复制上述版权声明、此条件列表和以下免责声明。

本软件由版权持有人和贡献者“按现状”提供,不提供任何明示或暗示的保证,包括但不限于对适销性和特定用途适用性的暗示保证。在任何情况下,版权持有人或贡献者均不对任何直接、间接、偶发、特殊、示例性或后果性损害(包括但不限于因替代商品或服务的采购、使用损失、数据或利润损失造成的损害,或业务中断)承担责任,无论何种原因和责任理论,无论是合同、严格责任或侵权(包括疏忽或其他原因),即使已告知可能性,也与本软件的使用有关。

作者

c64bob

许可证

2bsd

依赖项

luajit >= 2.1.0

版本