我正在尝试对数据字符串进行哈希处理,然后将结果复制到指针以便在其他地方使用(通过URL发送)。问题是,尽管哈希是正确的,但指针不包含正确的哈希。
int main(int argc, char const *argv[])
{
char data[] = "oNOH0hwZ3H6aduK5hnhxl5CI5C9v1EAghfO8maYfHUgKfQGn3NLeJdNEGNZyhqFpvjoIkcOSXUt2BZfvDQAcUeHqRxOZNke9ttHEvmmi7FbzugUXXl0HpxY7UDWyN1x6k5AGhNPfiQECXpqKAgiQE6NpzANcsb9D6AaedPklwOOk35Vtc3aGZOWoezrxBq1xR1CUHM63rLekGZEJSEgIi2XnreLSvCgctJX1mUVDvZO2OjBxOI6XATaSYMBjeImyh9puUaYfZC8ELA2p8YdyHdgvQIFUgRjoRyICzwHpZGUB6MR5BUu9YBvE90pfIytqX2SmoqCeXmFUZmPq79pVAKqzBFFa3YrRQa35rw9eIFYxSEOPE3B4ERu6m07gOoXvpRrGeqKMWzaE3OkxILsdtN9GD7MimAEBiV7mcIZY7Zt1EDpcfHfylf4PcHYp8sQhdNugmj4j9naDRpFWXLk9QeOTMC8KUPSYtc4FmZOldPOU4kGSVQRCVwmxYk8J0QyjTtO5ithm8W636CLSitl4QxsFIrfy7DIRXmM6FTiEFexCG9lPtwK9U2EsjJRhcpY0BBW7l4BR8ZjFYvlhRVgBNKUWjB4mRTcjkZgwTIdSxnnmIytqjASXbCKk4ExLnAUyp1U8AXRYa4aJtuZDUHqVa064vuGIUq69iR8IEPwFKxe4R4yBCPnCFkx1E3zokwosdn1I3odDLiytdWVFB887ivYMoo1yLfRPsJnlXrPzAeTD1E9tD7rLtgoIuf76lOLEoYQcgwCGAl9sP9Li73Uq98ZueWqqB2VPRBRXYjtpvtHasjjpc3Gc2vw7iNoJF9omB69pgsFBLdC4mLkpFRrycOvkrJUWJ98a57qcqWD2Z6XbI7rdOJCRnX2ExMq6Lp7HnoJDadwZaj1IgjMVSeC52uAp7QmJ6kgjzQNzT9pTihspq4b98D50YvgWctv8DCh2iUs2TIL2P4i6Yj5XN0OCmUooeKmHctAkeTcYrOQ6IZ2x9YkNPZf1KufO5rm7LMiP";
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512(data, sizeof(data) - 1, hash);
for(int i = 0; i < SHA512_DIGEST_LENGTH; ++i) {
printf("%02x", hash[i]);
}
unsigned char* phash = (unsigned char *)malloc(sizeof(hash));
memcpy(phash, hash, (sizeof(hash)));
printf("\nHash is: %p", *phash);
//some other code here
}
输出:a5274651e4573a7fea8dc1936a26a77a0667f600cad6c0afdd648431fa44b9e1e9128237b8012f103218f743cc422214701af609d22f9cbdf78e7bd5b374b87b(正确的哈希) 哈希为:0x564e7a3dc670
我在这里想念什么?