Pure LUA 5.2 implementation of HMAC_SHA256 algorithm, works in Fibaro Home Center 3. Also contains code for generating SHA256 of a string.
Paste the code into your LUA 5.2 script or Fibaro HC3 LUA scene, and then use hmac_sha256() function to have the string encrypted with HMAC_SHA256. Or use sha256() to generate SHA256 of a string.
Useful for making API calls, for example those with Tuya API. HMAC_SHA256 is used in authentication.
Usage example for hmac_256 (assuming the whole function code was copied and pasted into the script):
local client_id = "abc"
local secret = "abcdefgh"
local timestamp = "123" --Current time in miliseconds
local nonce = "456abce" --Random value like Python os.urandom(16) would return
local message = client_id .. timestamp .. nonce
print("Message:", message)
local signature = hmac_sha256(secret, message) --first key, then content, both strings
print("Generated Signature:", signature)