The different of SHA512 between openssl and php
Posted
by
solomon_wzs
on Stack Overflow
See other posts from Stack Overflow
or by solomon_wzs
Published on 2012-10-23T16:25:44Z
Indexed on
2012/10/23
17:00 UTC
Read the original article
Hit count: 162
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?? ?#? 6p?8jD????J?b9?????^X?
Here is PHP code:
$hash=hash('sha512', 'GFLOuJnR19881218', TRUE);
The output:
?<??>4??j??II?-A[r???? ??#??D6p?8jD???????J?b9?????^X?
The results of C code and PHP code are different, what is wrong with my code?
© Stack Overflow or respective owner