在计算硬编码字符串的哈希值时,我得到了一个正确的值。
unsigned char digest[MD5_DIGEST_LENGTH];
char string[] = "fnamelname";
MD5((unsigned char*)&string, strlen(string), (unsigned char*)&digest);
char mdString[33];
for(int i = 0; i < 16; i++)
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
printf("fullName: %s\n", string);
printf("md5 digest: %s\n", mdString);
在计算准备好的字符串的哈希值时,我得到了一个不正确/更改的哈希值。
char* fname = "fname";
char* lname = "lname";
char* fullname = new char[strlen(fname) + strlen(lname) + 1];
strcpy(fullname, fname);
strcat(fullname, lname);
MD5((unsigned char*) &fullname, strlen(fullname), (unsigned char*) &digest);
char mdString1[33];
for (int i = 0; i < 16; i++)
sprintf(&mdString1[i * 2], "%02x", (unsigned int) digest[i]);
printf("fullname: %s\n", fullname);
printf("md5 digest: %s\n", mdString1);