• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Lekensteyn/luagcrypt: luagcrypt is a Lua interface to the libgcrypt library, wri ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Lekensteyn/luagcrypt

开源软件地址(OpenSource Url):

https://github.com/Lekensteyn/luagcrypt

开源编程语言(OpenSource Language):

C 53.3%

开源软件介绍(OpenSource Introduction):

Build Status Build status Coverage Status

luagcrypt

Luagcrypt is a Lua binding to the Libgcrypt cryptographic library. Symmetric encryption/decryption (AES, etc.) and hashing (MD5, SHA-1, SHA-2, etc.) are supported.

It is compatible with Lua 5.1, 5.2 and 5.3 and runs on Linux, OS X and Windows.

Installation

The minimum requirement is Libgcrypt 1.4.2 (libgcrypt-11), but at least Libgcrypt 1.6.0 (libgcrypt-20) is recommended. After ensuring that the Lua and Libgcrypt development headers and libraries are available, you can invoke make to build luagcrypt.so with Lua 5.2. See the Makefile file for available variables.

An alternative cross-platform method uses LuaRocks. Once you have checked out this repository, you can invoke:

luarocks make

Note for Windows users: the rockspec file uses libgcrypt-20 which is used since Wireshark 1.12. Older Wireshark versions use Libgcrypt 1.4.6 (libgcrypt-11). Header files and precompiled libraries (libgcrypt-20.dll and its dependency libgpg-error-0.dll) can be found here:

  • Libgcrypt 1.8.3 for Wireshark 3.0: 64-bit, 32-bit (libgcrypt-20.dll, should be compatible with Wireshark 2.4 as well)
  • Libgcrypt 1.7.6 for Wireshark 2.4/2.6: 64-bit, 32-bit (libgcrypt-20.dll)
  • Libgcrypt 1.6.2 for Wireshark 2.2/2.0/1.12: 64-bit, 32-bit (libgcrypt-11.dll)

Be sure to build with Lua 5.2 (64-bit, 32-bit) if you intend to use the library with Wireshark.

Documentation

The interface closely mimics the Libgcrypt API. The following text assume the module name to be gcrypt = require("luagcrypt") for convenience.

Available functions under the module scope:

For the documentation of available functions, see the Libgcrypt manual. The above constructors correspond to the gcry_*_open routines. Resource deallocation (gcry_*_close) are handled implicitly by garbage collection. Length parameters are omitted when these can be inferred from the string length. For example, Libgcrypt's gcry_cipher_setkey(cipher, key, key_len) matches cipher:setkey(key) in Lua.

An error is thrown if any error occurs, that is, when the Libgcrypt functions return non-zero. (The error message text may change in the future.)

Constants like GCRY_CIPHER_AES256 are exposed as gcrypt.CIPHER_AES256 (without the GCRY_ prefix).

Example

The test suite contains representative examples, see luagcrypt_test.lua.

Another full example to calculate a SHA-256 message digest for standard input:

local gcrypt = require("luagcrypt")
-- Initialize the gcrypt library (required for standalone applications that
-- do not use Libgcrypt themselves).
gcrypt.init()

-- Convert bytes to their hexadecimal representation
function tohex(s)
    local hex = string.gsub(s, ".", function(c)
        return string.format("%02x", string.byte(c))
    end)
    return hex
end

local md = gcrypt.Hash(gcrypt.MD_SHA256)

-- Keep reading from standard input until EOF and update the hash state
repeat
    local data = io.read(4096)
    if data then
        md:write(data)
    end
until not data

-- Extract the hash as hexadecimal value
print(tohex(md:read()))

Tests

The basic test suite requires just Libgcrypt and Lua and can be invoked with make check (which invokes luagcrypt_test.lua).

Run the code coverage checker with:

make checkcoverage LUA_DIR=/usr

License

Copyright (c) 2016 Peter Wu [email protected]

This project ("luagcrypt") is licensed under the MIT license. See the LICENSE file for more details.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap