global sha2
Hashes conform sha2
This library is a side effect of the pdfe
library that needs such
helpers. The sha2.digest256
, sha2.digest384
and
sha2.digest512
functions accept a string and return a string with the
hash.
https://github.com/contextgarden/pplib https://gitlab.lisn.upsaclay.fr/texlive/luatex/-/blob/f52b099f3e01d53dc03b315e1909245c3d5418d3/source/libs/pplib/pplib-src/src/util/utilsha.c
😱 Types incomplete or incorrect? 🙏 Please contribute!
methods
sha2.digest256
@return - binary string
😱 Types incomplete or incorrect? 🙏 Please contribute!
Example:
local function to_hex(str)
return (str:gsub('.', function (c)
return string.format('%02x', string.byte(c))
end))
end
print(to_hex(sha2.digest256('test')))
-- 9f86d081... (length 64)
Reference:
- Corresponding C source code: md5lib.c#L199-L210
sha2.digest384
@return - binary string
😱 Types incomplete or incorrect? 🙏 Please contribute!
Example:
local function to_hex(str)
return (str:gsub('.', function (c)
return string.format('%02x', string.byte(c))
end))
end
print(to_hex(sha2.digest384('test')))
-- 76841232... (length 96)
Reference:
- Corresponding C source code: md5lib.c#L212-L223
sha2.digest512
@return - binary string
😱 Types incomplete or incorrect? 🙏 Please contribute!
Example:
local function to_hex(str)
return (str:gsub('.', function (c)
return string.format('%02x', string.byte(c))
end))
end
print(to_hex(sha2.digest512('test')))
-- ee26b0dd ... (length 128)
Reference:
- Corresponding C source code: md5lib.c#L225-L236