|
Project Information
|
OverviewLua binding for the SHA-256/384/512 BSD-licensed C implementation by Aaron Gifford[1]. Status
Changelog
Build & Install
After installation, please run test_sha2.lua and test_hmac.lua (the later needs LuaSocket and md5). Usagelocal function bintohex(s)
return (s:gsub('(.)', function(c)
return string.format('%02x', string.byte(c))
end))
end
require "sha2"
print(sha2.sha256hex("And so we say goodbye to our beloved pet, Nibbler, who's gone to a place where I, too, hope one day to go. The toilet."))
-- prints 3c4ba860b4917a85b075f5e0c8cebe65bd1646d0d5ac3326a974ae965a44a5e1
require "hmac.sha2"
print(bintohex(hmac.sha256("what do ya want for nothing?", "Jefe"))) --Jefe is the key
-- prints 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
require "hmac"
require "hmac.md5" --get md5 from LuaRocks
print(bintohex(hmac.md5("what do ya want for nothing?", "Jefe"))) --Jefe is the key
-- prints 750c783e6ab0b503eaa86e310a5db738Referencerequire "sha2" sha2.sha256(message) -> SHA256 binary hash string sha2.sha384(message) -> SHA348 binary hash string sha2.sha512(message) -> SHA512 binary hash string sha2.sha256hex(message) -> SHA256 hex hash string sha2.sha384hex(message) -> SHA348 hex hash string sha2.sha512hex(message) -> SHA512 hex hash string require "hmac" hmac.compute(key, message, hash_function, blocksize, [opad], [ipad]) -> HMAC string, opad, ipad hmac.new(hash_function, block_size) -> function(message, key) -> HMAC string require "hmac.sha2" hmac.sha256(message, key) -> HMAC-SHA256 binary string hmac.sha348(message, key) -> HMAC-SHA348 binary string hmac.sha512(message, key) -> HMAC-SHA512 binary string require "hmac.md5" hmac.md5(message, key) -> HMAC-MD5 binary string TODO
Feedback
Alternative implementations
|