I want to get hash of a binary file whose name I have. I have tried the following, but then realized that SHA1()
is returning hash value for the string ( name o
Thanks to everyone's comments I solved the problem. I am posting the code here, so others might find it beneficial.
void getFileHash(char *fileName){
unsigned char result[2*SHA_DIGEST_LENGTH];
unsigned char hash[SHA_DIGEST_LENGTH];
int i;
FILE *f = fopen(fileName,"rb");
SHA_CTX mdContent;
int bytes;
unsigned char data[1024];
if(f == NULL){
printf("%s couldn't open file\n",fileName);
exit(1);
}
SHA1_Init(&mdContent);
while((bytes = fread(data, 1, 1024, f)) != 0){
SHA1_Update(&mdContent, data, bytes);
}
SHA1_Final(hash,&mdContent);
for(i=0;i