This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

encode-decode password in apps
#1
Hello,
i need encode/decode password from alarm system in my apps (variable in storage) by MAC addr.

Is supported any sha or md5 encode/decode in encdec library?
or
how to use libcrypt.so ??? over ffi? how?

I apologize for my bad English and thank you.

MEREL
Reply
#2
Docs: http://openrb.com/docs/lua.htm#encded-info
Reply
#3
(10.10.2018, 16:47)admin Wrote: Docs: http://openrb.com/docs/lua.htm#encded-info

Thank you for your quick reply.

my task:
1. password must be encrypted by HW specific key (mac address)
2. aftter restore project on diferent HW, the password must not be visible. 
In my opinion I wish rsa function how to?

Thank you.

Code:
require('encdec')
password="1*1234"
key=io.readfile('/sys/class/net/eth0/address'):trim() -- or "/proc/device-tree/uniqid" or combination MAC and uniqid


-- encdec.md5(password)            -- get only hash md5
-- encdec.sha1(password)        -- get only hash sha1
-- encdec.crc16(password)        -- get crc
secret=encdec.base64enc(password)    -- ok but is not encription
pwd_decoded=encdec.base64dec(secret)    -- ok but is not encription



sha_secret=encdec.sha256(password)        -- undocumented ( create sha256 hash)
encoded_pwd=encdec.hmacsha256(password, key)    -- undocumented ( create signature with key), do you have any function to get data with key?
Reply
#4
SHA/MD5 are one-way hashing algorithms, not suitable for two-way encryption/decryption. In your case probably some simple XOR can be used. Is the pin code always in 1 number + * + 4 numbers format?
Reply
#5
(13.10.2018, 18:12)admin Wrote: SHA/MD5 are one-way hashing algorithms, not suitable for two-way encryption/decryption. In your case probably some simple XOR can be used. Is the pin code always in 1 number + * + 4 numbers format?

Hello admin,

password is number of user + "*" + user password ( 4 or 8 digit )
for example:

2*1111 or 2*11112222
3*1111 or 3*11112222


Originally I wanted to use RSA encryption/decription but I did not find the solution in pure LUA.
The second idea was to use openssl and os.execute but solution in lua is better.

Thank you verry much.
Reply
#6
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:
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)
Reply
#7
Thank Admi you very good help. Its work, thank you very much.
Reply


Forum Jump: