Skip to content
Branch: master
Go to file
Code
This branch is 2 commits ahead, 1 commit behind moteus:master.

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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

You can’t perform that action at this time.