lua-resty-string icon indicating copy to clipboard operation
lua-resty-string copied to clipboard

lua use resty.aes Encrypted hex result diff from c++ use openssl

Open RikLg opened this issue 11 years ago • 1 comments

the same key and the same mesg, but the result is different, why? lua: local key = "1" local mesg = "2"

local aes_256_cbc_sha1x5 = aes:new(key, salt, aes.cipher(256,"cbc"), aes.hash.sha1, 5) local encrypted = aes_256_cbc_sha1x5:encrypt(mesg) ngx.say("AES 256 CBC (SHA-1, salted) Encrypted HEX: ", str.to_hex(encrypted))

AES 256 CBC (SHA-1, salted) Encrypted HEX: 619a1da54b6c5113eb335a74296fed54

c++: int i, nrounds = 5; unsigned char key[32], iv[32];

i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), NULL, key_data, key_data_len, nrounds, key, iv);

... hex:1671d15e1905d518201b35064043cb71

to_hex api invoke ngx_hex_dump, it developed by C , same to my own c++ coding, but the result's display is different, Why???

RikLg avatar Sep 05 '14 06:09 RikLg

@peak1860 In Lua, strings are not null-terminated as in C or C++. This is likely where the difference is coming from.

chase avatar Mar 02 '15 17:03 chase