calog/examples/scripts/libraries/crypto.lua

20 lines
708 B
Lua

-- Showcase the calog crypto library: hashing, HMAC, base64/hex round-trips,
-- UUID generation, and random bytes.
-- Run: bin/calog examples/scripts/libraries/crypto.lua
calogPrint("sha256(abc):", cryptoHashSha256("abc"))
calogPrint("sha1(abc):", cryptoHashSha1("abc"))
calogPrint("hmacSha256(key,abc):", cryptoHmacSha256("key", "abc"))
local b64 = cryptoBase64Encode("hello world")
calogPrint("base64 encode:", b64)
calogPrint("base64 decode:", cryptoBase64Decode(b64))
local hex = cryptoHexEncode("hello world")
calogPrint("hex encode:", hex)
calogPrint("hex decode:", cryptoHexDecode(hex))
calogPrint("uuid:", cryptoUuid())
calogPrint("randomBytes(16) length:", #cryptoRandomBytes(16))
calogExit(0)