Skip to content

superfly/lua-bgcrypto-sha

 
 

Repository files navigation

lua-bgcrypto-sha

Build Status Build status Coverage Status

Digest API

Digest.new() => Digest context

Each MESSAGE can be present like

  • message [,offset=1 [, size=<END OF MESSAGE>]] if message is string
  • message [,offset=1], size if message is raw pointer to memory (light userdata)

Digest.digest(MESSAGE [, text = false]) => string

Digest.pbkdf2(password, salt, iterations, key_length) => string

digest:update(MESSAGE) => self

digest:digest([MESSAGE ,] [text = false]) => self

digest:reset() => self

digest:clone() => self

HMAC API

Digest.hmac.new(key) => HMAC Context

Digest.hmac.digest(key, MESSAGE[, text = false]) => string

hmac:update(MESSAGE) => self

hmac:digest([MESSAGE ,] [text = false]) => self

hmac:reset([key]) => self

hmac:clone() => self

Usage

local sha1 = require "bgcrypto.sha1"
local key = "\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11"
local msg = "The quick brown fox jumps over the lazy dog"

print(sha1.digest(msg, true))

print(sha1.hmac.digest(key, msg, true))

local ctx = sha1.new()
for i = 1, #msg do ctx:update(msg, i, 1) end
print(ctx:digest(true))

local ctx = sha1.hmac.new(key)
for i = 1, #msg do ctx:update(msg, i, 1) end
print(ctx:digest(true))

print(ctx:reset(key):update(msg:sub(1, 25)):digest(msg:sub(26), true))

print(string.format("%q", sha1.pbkdf2('secret', '123salt', 1000, 32)))

See AesFileEncrypt implementation using lua-bgcrypto library.

Bitdeli Badge

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 45.6%
  • Lua 30.8%
  • Batchfile 11.6%
  • C++ 10.3%
  • Shell 1.7%