问题
I have the following code to calculate the sha512 hash:
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
int main() {
char *password = "test";
char hash[SHA512_DIGEST_LENGTH];
SHA512(password, strlen(password), hash);
return 0;
}
How to print out the calculated hash in hex?
Thanks
回答1:
Change hash
to be unsigned char hash[SHA512_DIGEST_LENGTH]
. Then:
for(int i = 0; i < SHA512_DIGEST_LENGTH; ++i) {
printf("%02x", hash[i]);
}
来源:https://stackoverflow.com/questions/36381509/how-to-print-sha512-hash-in-c