Hi,
There is a confusion in your code between byte buffers and their HEX
representation. You should work directly with buffer without trying to
access them as strings. This will solve all your problems.
So, change the implementation of your function MD5_hash to put the hash
directly into the chash parameter without converting it to ASCII and
never call printf directly on byte arrays.
Once you have done these changes and if you still have errors, post your
code and we will try to help you.
Cheers,
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr
himas wrote:
Mounir IDRASSI wrote:
Hi,
There are two main mistakes in your code:
- The output of the MD5 is 16 bytes long but you are allocating 8
bytes only. This will cause memory corruption.
- AES-256 expects the key to be 32-bytes long but you want to use an
MD5 digest as a key which is only 16-bytes. You should use SHA-256
instead for this purpose.
1. I tried to allocate more, but got some extra-symbols returned with the
hash
char *chash = (char*)malloc(16);
MD5_Hash(pass, chash);
printf("%s \n", chash);
returned:
"Р♥>3dd0cd797a7399b56c470612887108eb"
2. Just for the test I doubled my MD5 digest and send it to Decryption
function and got the same sad result
new ctext = "fdfb4ca253caf79c683b85787de8d094"
as you can see it remains the same after doubling the hash
---------- CODE ----------
// double the key
char hash[65] = {0};
int i;
for (i = 0; i <= 64; i++)
{
if (i >= 32) hash[i] = chash[i-32];
else hash[i] = chash[i];
}
hash[65] = '\0';
printf("%s \n", hash);
---------- CODE ----------
Result:
[*] decryption result
ae e3 27 62 c8 8a 9a 76 0b 67 73 1e 17 f8 dc ca
оу'b╚КЪv♂gs▲↨°▄╩tСTUT*ыьЫuУ{╧$Qо
3. I also changed a little my Decryption code:
---------- CODE ----------
int templen;
EVP_DecryptFinal(&ctx, outbuf + outlen, &templen);
outlen = outlen + templen;
---------- CODE ----------
SO
---------- CODE ----------
for(i = 0; i < outlen; i++) printf("%02x ", outbuf[i]);
---------- CODE ----------
Now works fine
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager majord...@openssl.org