25.04.2019, 09:28
Hi Admin,
Yes I found out that it can actually be decoded with AES256, but not with the lua aes library that was shared on this forum.
Rijndael 128 is actually AES with a 256bits key size.
There must be something wrong in aes library because it can encrypt and decrypt itself fine, but it cannot decode my strings properly, and it does not encode the same way either.
I have tried many different combinations, and it never produces the same result as you would get from other tools.
Some issues about this were opened in Github, but with not much success it seems.
I think someone rewrote part of the code to solve the problem, but I am not sure it can be implemented on LM.
The original php code does this:
I came up with this code that is supposed to do the same thing:
But that does not give any results if I try to decode something that is known to work.
Here is an example.
The following code should give me {"id":"/system/brand","type":"stringValue","writeable":0,"recordable":0,"value":"Buderus"}
But the result is nil.
And if you run the input and key in any online decryption tools, it works fine.
user.aes is the library that was shared in the thread https://forum.logicmachine.net/showthread.php?tid=1643[url=https://forum.logicmachine.net/showthread.php?tid=1643][/url]
I am open to any suggestions.
Regards.
Michel.
Yes I found out that it can actually be decoded with AES256, but not with the lua aes library that was shared on this forum.
Rijndael 128 is actually AES with a 256bits key size.
There must be something wrong in aes library because it can encrypt and decrypt itself fine, but it cannot decode my strings properly, and it does not encode the same way either.
I have tried many different combinations, and it never produces the same result as you would get from other tools.
Some issues about this were opened in Github, but with not much success it seems.
I think someone rewrote part of the code to solve the problem, but I am not sure it can be implemented on LM.
The original php code does this:
Code:
$decrypt = (mcrypt_decrypt( MCRYPT_RIJNDAEL_128, km200_crypt_key_private, base64_decode($decryptData), MCRYPT_MODE_ECB, '' ) );
I came up with this code that is supposed to do the same thing:
Code:
local ctx = aes:new(km200_crypt_key_private, nil, aes.cipher(256,"ecb"))
local res = ctx:decrypt(encdec.base64dec(decryptData))
log ('decryptedData: ', res)
Here is an example.
The following code should give me {"id":"/system/brand","type":"stringValue","writeable":0,"recordable":0,"value":"Buderus"}
But the result is nil.
And if you run the input and key in any online decryption tools, it works fine.
Code:
encrypteddata = '88a2296d072f83992af086fd293aefa4090acb9e6e8790844fdea4ab3a8604b5ab8871ba73614c8885ebaf434cc6bef54e8eed26f980586525a59b585e69f3fc03c8fcf28bb1648cb0b06e404a8deb719067791d14e339797174eb7dddb1a277'
key = '4aca89d6389f79303e2b58a0370cd7f7f8f1d560e45c66c0634862c184ddbaf7'
--base64 private key: SsqJ1jifeTA+K1igNwzX9/jx1WDkXGbAY0hiwYTduvc=
--hex private key: 4aca89d6389f79303e2b58a0370cd7f7f8f1d560e45c66c0634862c184ddbaf7
--base64 encrypted string: iKIpbQcvg5kq8Ib9KTrvpAkKy55uh5CET96kqzqGBLWriHG6c2FMiIXrr0NMxr71To7tJvmAWGUlpZtYXmnz/API/PKLsWSMsLBuQEqN63GQZ3kdFOM5eXF0633dsaJ3
--hex encrypted string: 88a2296d072f83992af086fd293aefa4090acb9e6e8790844fdea4ab3a8604b5ab8871ba73614c8885ebaf434cc6bef54e8eed26f980586525a59b585e69f3fc03c8fcf28bb1648cb0b06e404a8deb719067791d14e339797174eb7dddb1a277
--results: {"id":"/system/brand","type":"stringValue","writeable":0,"recordable":0,"value":"Buderus"}
function string.fromhex(str)
return (str:gsub('..', function (cc)
return string.char(tonumber(cc, 16))
end))
end
function string.tohex(str)
return (str:gsub('.', function (c)
return string.format('%02X', string.byte(c))
end))
end
aes = require('user.aes')
encdec = require ('encdec')
km200_crypt_key_private = string.fromhex(key)
log(encdec.base64enc(km200_crypt_key_private))
decryptData = string.fromhex(encrypteddata)
log(encdec.base64enc(decryptData))
local ctx = aes:new(km200_crypt_key_private, nil, aes.cipher(256,"ecb"))
local res = ctx:decrypt(decryptData)
log ('decryptData: ', res)
user.aes is the library that was shared in the thread https://forum.logicmachine.net/showthread.php?tid=1643[url=https://forum.logicmachine.net/showthread.php?tid=1643][/url]
I am open to any suggestions.
Regards.
Michel.