LuaCrypto
A Lua frontend to OpenSSL

Example

Below is a sample displaying the basic use of the library.
local crypto = require("crypto")

assert(io.input(some_file))
local md5_of_some_file = crypto.digest("md5", io.read("*all"))
   
assert(io.input(some_file))
local hmac_of_some_file = crypto.hmac("sha1", io.read("*all"), "hmackey")
And here is a sample of the object interface to the code.
require("crypto")

local evp = crypto.digest.new("md5")
for line in io.lines(some_file) do 
    evp:update(line)
end
local md5_of_some_file = evp:final()
A quick encryption/decryption example. Uses the Blowfish algorithm. You pass the key and source file from command line, following the operation. If no file is given, uses standard input.
require("crypto")
assert(#arg >= 2, "Usage: lua crypt.lua <encrypt/decrypt> <key> [file]")
cmd = arg[1]
key = arg[2]
file = #arg>2 and assert(io.open(arg[3], "rb")) or io.stdin
content = file:read("*a")
if cmd == "encrypt" then
  result = crypto.encrypt("blowfish", content, key)
else
  result = crypto.decrypt("blowfish", content, key)
end
io.write(result)

Valid XHTML 1.0!