问题
First thing I have to mention is I'm really really new to Lua and please be patient if you think my question is too dumb
Here is my requirement
- I need to use HMAC-sha256 for Lightroom plugin development as I'm using that for security.
I was trying to use this but with no luck https://code.google.com/p/lua-files/wiki/hmac
These are the steps I followed
- Got the code of https://code.google.com/p/lua-files/source/browse/hmac.lua and saved as 'hmac.lua' file in my plugin directory
- Got the code from this https://code.google.com/p/lua-files/source/browse/sha2.lua and saved as 'sha2.lua' file
Now in the file I use it like this
local hmac = require'hmac'
local sha2 = require'sha2'
--somewhere doend the line inside a function
local hashvalue = hmac.sha2('key', 'message')
but unfortunately this does not work and I'm not sure what I'm doing wrong. Can anyone advice me what I'm doing wrong here? Or is there an easier and better way of doing this with a good example.
EDIT: I'm doing this to get the result. When I include that code the plugin does stops working. I cannot get the output string when I do this
hashvalue = hmac.sha2('key', 'message')
local LrLogger = import 'LrLogger'
myLogger = LrLogger('FlaggedFiles')
myLogger:enable("logfile")
myLogger:trace ("=========================================\n")
myLogger:trace ('Winter is coming, ' .. hashvalue)
myLogger:trace ("=========================================\n")
and the Lightroom refuses to load the plugin and there is nothing on the log as well
Thank you very much for your help
回答1:
I'd first make sure your code works outside of Lightroom. It seems that HMAC module you referenced has some other dependencies: it requires "glue", "bit", and "ffi" modules. Of these, bit and ffi are binary modules and I'm not sure you will be able to load them into Lightroom (unless they are already available there). In any case, you probably won't be able to make it run in LR if you don't have required modules and can't make it run without issues outside of LR.
回答2:
If you just need to get SHA256 hash there is a way to do it Lightroom
I posted my question here and was able to get an answer. But there there was no reference of this on SDK documentation (Lightroom SDK)
local sha = import 'LrDigest'
d = sha.SHA256.digest ("Hello world")
but unfortunately there was no HMAC so I decided to use md5 with a salt because this was taking too much of my time
回答3:
Spent quite some time trying to find a solution :-/ LrDigest is not documented, thanks Adobe! Solution:
local LrDigest = import "LrDigest"
LrDigest.HMAC.digest(string, 'SHA256', key)
来源:https://stackoverflow.com/questions/24377945/how-to-use-hmac-in-lua-lightroom-plugin