How to print SHA512 hash in C [duplicate]

最后都变了- 提交于 2019-12-11 10:50:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!