如何在C中打印SHA512哈希 [英] How to print SHA512 hash in C
本文介绍了如何在C中打印SHA512哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来计算sha512哈希:
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?
谢谢
推荐答案
将hash
更改为unsigned char hash[SHA512_DIGEST_LENGTH]
.然后:
for(int i = 0; i < SHA512_DIGEST_LENGTH; ++i) {
printf("%02x", hash[i]);
}
这篇关于如何在C中打印SHA512哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文