22.10.2018, 06:38
Create a user library called aes by using this code:
https://github.com/openresty/lua-resty-s...ty/aes.lua
Add this before ffi.cdef... (line 21) to make it work on LM:
Encrypted data is raw binary so it's additional encoded into base64. CPU unique ID is used instead of MAC address becase MAC can be changed on OS level while CPU ID cannot.
https://github.com/openresty/lua-resty-s...ty/aes.lua
Add this before ffi.cdef... (line 21) to make it work on LM:
Code:
local lib = '/usr/lib/libcrypto.so'
if not io.exists(lib) then
lib = '/usr/lib/libcrypto.so.1.0.0'
end
ffi.load(lib, true)
Encrypted data is raw binary so it's additional encoded into base64. CPU unique ID is used instead of MAC address becase MAC can be changed on OS level while CPU ID cannot.
Code:
aes = require('aes')
require('encdec')
key = io.readfile('/proc/device-tree/uniqid')
ctx = aes:new(key)
res = ctx:encrypt('abcdef')
res = encdec.base64enc(res)
log(res)
ctx = aes:new(key)
res = encdec.base64dec(res)
res = ctx:decrypt(res)
log(res)