bungle / lua-resty-nettle

LuaJIT FFI bindings for Nettle (a low-level cryptographic library)
BSD 2-Clause "Simplified" License
182 stars 45 forks source link

aes decrypt issue #12

Closed qqlee closed 7 years ago

qqlee commented 7 years ago

local aes = require "resty.nettle.aes" local aes128 = aes.new("1234567812345678")

local str = "aaa" local ciphertext = aes128:encrypt(str) ngx.say(#str) -- print 3

local plaintext = aes128:decrypt(ciphertext) ngx.say(#plaintext) -- print 16

-- i need replace \0 local str = ngx.re.gsub(plaintext, [[\x00]], "") ngx.say(#str) --print 3

bungle commented 7 years ago

It is not an issue, see: resty.nettle.padding.*. Please pad before encrypting and unpad with similar algo after decrypting. We may add another parameter in a future. AES is a block cipher and it works in 16 bytes blocks. In binary formats \0 can mean something. Only way to to go forward, AFAIK, is to pad.

bungle commented 7 years ago

See also: https://github.com/bungle/lua-resty-nettle/issues/5

qqlee commented 7 years ago

thanks