Reputation: 309
I'm using Peter Deutsch's implementation of MD5 to implement a simple password check. I use it this way:
md5_state_t md;
char *in = "Hello World";
char *out[16];
md5_init(&md);
md5_append(&md, in, strlen(in));
md5_finish(&md, out);
printf("In: %s\n", in);
printf("Out: %s\n", out);
Problem is, that I get a result like this:
In: Hello World
Out: ?
??d?uA????.??
Does anyone has an idea whats going wrong here?
Upvotes: 0
Views: 222
Reputation: 229274
An MD5 hash is a binary blob of 16 bytes. You cannot print that as a string. Print it e.g. in a hex representation:
md5_state_t md;
char *in = "Hello World";
char out[16];
int i;
md5_init(&md);
md5_append(&md, in, strlen(in));
md5_finish(&md, out);
printf("In: %s\n", in);
printf("Out: ");
for(i = 0; i < 16: i++)
printf("%02X", out[i]);
puts("");
Note that the above changes out
to be a char as well, it can not be a char*
Upvotes: 3