I have been stuck for a day now on implementing openssl(on windows) md5. Such a simple thing seems like its taking forever. It crashes @ MD5_Update when ran. Is there something I am missing, and if I am, any helpful tips to improve my code so I never do it again? I followed these documents: http://www.openssl.org/docs/crypto/md5.html Thanks. I really do appreciate it. 🙂
#include <iostream>
#include <iomanip>
#include <openssl/md5.h>
using namespace std;
int main()
{
unsigned char data[] = {0xd1, 0x31, 0xdd, 0x02, 0xc5, 0xe6, 0xee, 0xc4, 0x69, 0x3d, 0x9a, 0x06, 0x98, 0xaf, 0xf9, 0x5c};
unsigned char hash[16];
MD5_CTX *c;
MD5_Update(c,data,16);
MD5_Final(hash, c);
for(int i=0;i<16;i++)
cout << setfill('0') << setw(2) << hex << (int)hash[i] << " ";
int a;
cin >> a;
return 0;
}
You never create, nor do you allocate space to hold, the MD5 context.
You can’t use a variable before you assign it a value! After your first line,
chas some arbitrary junk value, which you then pass toMD5_Update!Try: