Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RikLg opened this issue Sep 5, 2014 · 1 comment
Open

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

RikLg opened this issue Sep 5, 2014 · 1 comment

Comments

@RikLg
Copy link

RikLg commented Sep 5, 2014

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

@chase
Copy link
Contributor

chase commented Mar 2, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants