Logic Machine Forum
encode-decode password in apps - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: encode-decode password in apps (/showthread.php?tid=1643)



encode-decode password in apps - merel - 10.10.2018

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


RE: encode-decode password in apps - admin - 10.10.2018

Docs: http://openrb.com/docs/lua.htm#encded-info


RE: encode-decode password in apps - merel - 10.10.2018

(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?



RE: encode-decode password in apps - admin - 13.10.2018

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?


RE: encode-decode password in apps - merel - 15.10.2018

(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.


RE: encode-decode password in apps - admin - 22.10.2018

Create a user library called aes by using this code:
https://github.com/openresty/lua-resty-string/blob/master/lib/resty/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)



RE: encode-decode password in apps - merel - 25.10.2018

Thank Admi you very good help. Its work, thank you very much.