Here is C code:
#include <openssl/sha.h>
#include <stdio.h>
char *hash_sha512(char *data){
SHA512_CTX ctx;
char *md=malloc(sizeof(char)*(SHA512_DIGEST_LENGTH+1));
SHA512_Init(&ctx);
SHA512_Update(&ctx, data, strlen(data));
SHA512_Final(md, &ctx);
md[SHA512_DIGEST_LENGTH]='\0';
return md;
}
int main(int argc, char *argv[]){
str=hash_sha512("GFLOuJnR19881218");
printf("%s\n", str);
free(str);
return 1;
}
The output:
�<�4����IIA[r�� Η#� 6π�8jD����J�b9��ږ��^X�
Here is PHP code:
$hash=hash('sha512', 'GFLOuJnR19881218', TRUE);
The output:
�<��>4��ǰ��II�-A[r�?�� �Η#��D6π�8jD���?���J�b9��ږ��^X�
The results of C code and PHP code are different, what is wrong with my code?
The output is garbled because the output is a binary string which the browser is trying to display as ASCII or UTF-8 and can’t. You need to encode both as hexidecimal, decimal, base32, or some other normal human representation and then compare them.