I am using following code to print md5 and creating a string
char *hash = (char*)malloc(32 * sizeof(char));
unsigned *d = md5(msg, strlen(msg));
MD5union u;
printf("\n\n\nThe MD5 code for input string is : \n");
for (j=0;j<4; j++){
u.w = d[j];
for (k=0;k<4;k++)
{
char *mVal = (char*)malloc(sizeof(char));
sprintf(mVal, "%02x",u.b[k]);
strcat(hash, mVal);
printf("%02x",u.b[k]);
}
}
printf("\n\n\nThe MD5 code for input string is :%s \n", hash);
My output is
The MD5 code for input string is :
187ef4436122d1cc2f40dc2b92f0eba0
The MD5 code for input string is :p��187ef4436122d1cc2f40dc2b92f0eba0
Why is there p��
extra in my hash value