如何在 C 中打印 SHA512 哈希

How to print SHA512 hash in C

我有以下代码来计算 sha512 哈希值:

#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;
}

如何以十六进制打印出计算出的哈希值?

谢谢

hash 更改为 unsigned char hash[SHA512_DIGEST_LENGTH]。那么:

for(int i = 0; i < SHA512_DIGEST_LENGTH; ++i) {
   printf("%02x", hash[i]);
}