0

I have installed lua-resty-hmac and luacrypto from luarocks and want to perform encryption using hmac and sha1 in Lua. I have gone through the following thread How to use HMAC in Lua - Lightroom plugin. I am trying the following

local hmac = require'hmac'
local sha2 = require'sha2'
local hashvalue = hmac.sha2('key', 'message') 

But when I execute this I get the following error -

lua: /home/agile/Music/works/Lua/lua-resty-hmac-master/lib/resty/hmac.lua:4: module 'crypto' not found:
    no field package.preload['crypto']
    no file './crypto.lua'
    no file '/usr/share/lua/5.1/crypto.lua'
    no file '/usr/share/lua/5.1/crypto/init.lua'
    no file '/usr/lib64/lua/5.1/crypto.lua'
    no file '/usr/lib64/lua/5.1/crypto/init.lua'
    no file '/home/agile/Music/works/Lua/lua-resty-hmac-master/lib/resty/crypto.lua'
    no file './crypto.so'
    no file '/usr/lib64/lua/5.1/crypto.so'
    no file '/usr/lib64/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    /home/agile/Music/works/Lua/lua-resty-hmac-master/lib/resty/hmac.lua:4: in main chunk
    [C]: in function 'require'
    3.lua:2: in main chunk
    [C]: ?

Please suggest where I am doing wrong.

Community
  • 1
  • 1
Sudip
  • 1
  • 3
  • you need install lua-crypto I think. – moteus Feb 02 '16 at 09:56
  • I have already installed luacrypto from luarocks – Sudip Feb 02 '16 at 10:04
  • So is it in your library path? – llogiq Feb 02 '16 at 10:09
  • the exception says it can not find 'crypto.lua'. When I perform locate 'crypto.lua' from my root directory I did not find anything. But I have install luacrypto and it was a success. Please suggest where I am going wrong. – Sudip Feb 02 '16 at 10:21
  • lua-crypto is single so/dll file. so do `luarocks show crypto` to find where it installed and add path to LUA_CPATH env (you can use `luarocks path` to find all paths) – moteus Feb 02 '16 at 10:59
  • @moteus Thanks for your help. But when I perform 'luarocks show crypto', get the following error - Error: cannot find package crypto. Please suggest how to get crypto. I am using fedora system. – Sudip Feb 02 '16 at 11:30
  • It name is `luacrypto` so try this name. `luarocks show luacrypto` – moteus Feb 02 '16 at 11:39
  • Doing 'luarocks show luacrypto' gives me the following - Modules: crypto (/home/agile/.luarocks/lib/lua/5.1/crypto.so). It could not find 'crypto.lua'. Also when I go to the path '/home/agile/.luarocks/lib/lua/', there is no folder named '5.1'. – Sudip Feb 02 '16 at 11:57
  • I really can not understand where I am wrong. Please help. – Sudip Feb 02 '16 at 12:10
  • You do not need `crypto.lua` only `crypro.so`. Now you search this only in `/usr/lib64/lua/5.1/?.so`. You need add also `/home/agile/.luarocks/lib/lua/5.1/?.so`. Do `luarocks path` and it shouws paths you need add to your env – moteus Feb 02 '16 at 12:21
  • Thanks @moteus. I added '/home/agile/.luarocks/lib/lua/5.1/?.so' in package.path. It is now able find crypto.so. Thanks a lot. – Sudip Feb 02 '16 at 12:40
  • @moteus It might be a good idea to add this as an answer or - if it is too generic - the question could be closed or deleted. That's also up to you Sudip, it seems you've got the answer you are looking for, so the only question remaining is if the question is of use to anybody else. – Maarten Bodewes Feb 02 '16 at 22:23
  • Definitely of use to somebody else! Me. Thank you @moteus. – AaronDanielson Jul 15 '16 at 18:00

0 Answers0