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.

Rijndael 128 decrypting?
#4
There are two issues here that cause data errors:
1. aes.lua hashes the secret key
2. PHP uses different padding for secret key and data.

Solution:
1. Use this aes library which supports turning off padding: https://github.com/openresty/lua-resty-s...ty/aes.lua
2. Add library loading as mentioned in this post: https://forum.logicmachine.net/showthrea...7#pid10237

Working example for decrypt:
Code:
function pad(str, bits)
  local bytes = bits / 8
  local rem = #str % bytes

  if rem > 0 then
    str = str .. string.rep('\0', bytes - rem)
  end

  return str
end

encdec = require('encdec')
aes = require('aes')

key = encdec.base64dec('SsqJ1jifeTA+K1igNwzX9/jx1WDkXGbAY0hiwYTduvc=')
data = encdec.base64dec('iKIpbQcvg5kq8Ib9KTrvpAkKy55uh5CET96kqzqGBLWriHG6c2FMiIXrr0NMxr71To7tJvmAWGUlpZtYXmnz/API/PKLsWSMsLBuQEqN63GQZ3kdFOM5eXF0633dsaJ3')

hash = { iv = string.rep('\0', 16) } -- no hashing method for key
aes_256_ecb, err = aes:new(pad(key, 256), nil, aes.cipher(256, 'ecb'), hash, nil, 0)
res = aes_256_ecb:decrypt(pad(data, 128)) -- data block size is always 128 bits

log(res)
Reply


Messages In This Thread
Rijndael 128 decrypting? - by MichelDeLigne - 24.04.2019, 13:16
RE: Rijndael 128 decrypting? - by admin - 25.04.2019, 07:02
RE: Rijndael 128 decrypting? - by admin - 25.04.2019, 10:20

Forum Jump: