0
votes

There is a Node.JS code which creates a signature for Azure.

var signature = crypto.createHmac("sha256", key).update(body).digest("base64");  

How can I create the same signature using LUA. (I think I need to use Lua-Lockbox for this)

https://github.com/somesocks/lua-lockbox

I can see it has Hmac, sha256 and base64 primitives but I'm not sure how I can implement this code as LUA

Is there any clue?

1

1 Answers

1
votes

I don't know lua-lockbox, but it looks like this should work:

local stream = require "lockbox.util.stream"
local hmac = require "lockbox.mac.hmac"
local sha256 = require "lockbox.digest.sha2_256"
local base64 = require "lockbox.util.base64"

local body = stream.fromString("thisisthebody")
local key = {("thekey"):byte(1,-1)}

local digest = hmac()
    .setBlockSize(64)
    .setDigest(sha256)
    .setKey(key)
    .init()
    .update(body)
    .finish()
    .asBytes()

local base64_digest = base64.fromArray(digest)

print(base64_digest)