在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bungle/lua-resty-nettle开源软件地址(OpenSource Url):https://github.com/bungle/lua-resty-nettle开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):lua-resty-nettleLuaJIT FFI bindings for Nettle (a low-level cryptographic library) RequirementsThe bindings require Bindings are tested with Linux and macOS on x64 architecture, but I don't see any reason why they wouldn't work with other platforms and architectures. Synopsislocal require = require
local print = print
local gsub = string.gsub
local byte = string.byte
local format = string.format
local ipairs = ipairs
local concat = table.concat
local function hex(str,spacer)
return (gsub(str,"(.)", function (c)
return format("%02X%s", byte(c), spacer or "")
end))
end
do
local md2 = require "resty.nettle.md2"
print("md2 ", #md2(""), hex(md2("")))
local hash = md2.new()
hash:update("")
print("md2 ", #hash:digest(), hex(hash:digest()))
end
do
local md4 = require "resty.nettle.md4"
print("md4 ", #md4(""), hex(md4("")))
local hash = md4.new()
hash:update("")
print("md4 ", #hash:digest(), hex(hash:digest()))
end
do
local md5 = require "resty.nettle.md5"
print("md5 ", #md5(""), hex(md5("")))
local hash = md5.new()
hash:update("")
print("md5 ", #hash:digest(), hex(hash:digest()))
end
do
local ripemd160 = require "resty.nettle.ripemd160"
local hash = ripemd160.new()
hash:update("")
print("ripemd160", #hash:digest(), hex(hash:digest()))
end
do
local gosthash94 = require "resty.nettle.gosthash94"
local hash = gosthash94.new()
hash:update("")
print("gosthash94", #hash:digest(), hex(hash:digest()))
end
do
local sha1 = require "resty.nettle.sha1"
print("sha1 ", #sha1(""), hex(sha1("")))
local hash = sha1.new()
hash:update("")
print("sha1 ", #hash:digest(), hex(hash:digest()))
end
do
local sha2 = require "resty.nettle.sha2"
local hash = sha2.sha224.new()
hash:update("")
print("sha224 ", #hash:digest(), hex(hash:digest()))
print("sha224 ", #sha2.sha224(""), hex(sha2.sha224("")))
local hash = sha2.sha256.new()
hash:update("")
print("sha256 ", #hash:digest(), hex(hash:digest()))
print("sha256 ", #sha2.sha256(""), hex(sha2.sha256("")))
local hash = sha2.sha384.new()
hash:update("")
print("sha384 ", #hash:digest(), hex(hash:digest()))
print("sha384 ", #sha2.sha384(""), hex(sha2.sha384("")))
local hash = sha2.sha512.new()
hash:update("")
print("sha512 ", #hash:digest(), hex(hash:digest()))
print("sha512 ", #sha2.sha512(""), hex(sha2.sha512("")))
local hash = sha2.sha512_224.new()
hash:update("")
print("sha512_224", #hash:digest(), hex(hash:digest()))
print("sha512_224", #sha2.sha512_224(""), hex(sha2.sha512_224("")))
local hash = sha2.sha512_256.new()
hash:update("")
print("sha512_256", #hash:digest(), hex(hash:digest()))
print("sha512_256", #sha2.sha512_256(""), hex(sha2.sha512_256("")))
end
do
local sha3 = require "resty.nettle.sha3"
local hash = sha3.sha224.new()
hash:update("")
print("sha3 224", #hash:digest(), hex(hash:digest()))
local hash = sha3.sha256.new()
hash:update("")
print("sha3 256", #hash:digest(), hex(hash:digest()))
local hash = sha3.sha384.new()
hash:update("")
print("sha3 384", #hash:digest(), hex(hash:digest()))
local hash = sha3.sha512.new()
hash:update("")
print("sha3 512", #hash:digest(), hex(hash:digest()))
end
do
local hmac = require "resty.nettle.hmac"
print("hmac md5", #hmac("md5", "a", "a"), hex(hmac("md5", "a", "a")))
print("hmac md5", #hmac.md5("a", "a"), hex(hmac.md5("a", "a")))
local hash = hmac.md5.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac md5", #dgst, hex(dgst))
local hash = hmac.ripemd160.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac ripemd160", #dgst, hex(dgst))
local hash = hmac.sha1.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac sha1", #dgst, hex(dgst))
local hash = hmac.sha224.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac sha224", #dgst, hex(dgst))
local hash = hmac.sha256.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac sha256", #dgst, hex(dgst))
local hash = hmac.sha384.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac sha384", #dgst, hex(dgst))
local hash = hmac.sha512.new("a")
hash:update("a")
local dgst = hash:digest()
print("hmac sha512", #dgst, hex(dgst))
end
do
local umac = require "resty.nettle.umac"
local hash = umac.umac32.new("umac32")
hash:update("")
local dgst = hash:digest()
print("umac32 ", #dgst, hex(dgst))
local hash = umac.umac64.new("umac64")
hash:update("")
local dgst = hash:digest()
print("umac64 ", #dgst, hex(dgst))
local hash = umac.umac96.new("umac96")
hash:update("")
local dgst = hash:digest()
print("umac96 ", #dgst, hex(dgst))
local hash = umac.umac128.new("umac128")
hash:update("")
local dgst = hash:digest()
print("umac128 ", #dgst, hex(dgst))
end
do
local poly = require "resty.nettle.poly1305"
local hash = poly.new("poly")
hash:update("")
local dgst = hash:digest()
print("poly1305 ", #dgst, hex(dgst))
end
do
local pbkdf2 = require "resty.nettle.pbkdf2"
local hmac = pbkdf2.hmac_sha1("password", 1, "salt", 20)
print("pbkdf2 sha1", #hmac, hex(hmac))
local hmac = pbkdf2.hmac_sha256("pass\0word", 4096, "sa\0lt", 32)
print("pbkdf2 sha256", #hmac, hex(hmac))
end
print()
do
local aes = require "resty.nettle.aes"
local aes128 = aes.new("testtesttesttest")
local ciphertext = aes128:encrypt("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
print("aes128 encrypt", #ciphertext, hex(ciphertext))
local aes128 = aes.new("testtesttesttest")
local plaintext = aes128:decrypt(ciphertext)
print("aes128 decrypt", #plaintext, plaintext)
print()
local aes128 = aes.new("testtesttesttest", "cbc", "testtesttesttest")
local ciphertext = aes128:encrypt("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
print("aes128 cbc enc", #ciphertext, hex(ciphertext))
local aes128 = aes.new("testtesttesttest", "cbc", "testtesttesttest")
local plaintext = aes128:decrypt(ciphertext)
print("aes128 cbc dec", #plaintext, plaintext)
print()
local aes128 = aes.new("testtesttesttest
全部评论
专题导读
上一篇:SirAnthony/slpp: Simple lua-python parser发布时间:2022-08-16下一篇:ers35/luakernel: Lua + SQLite + musl libc running on x86.发布时间:2022-08-16热门推荐
热门话题
阅读排行榜
|
请发表评论