Sha256 is giving junk output
Posted
by
user1746617
on Stack Overflow
See other posts from Stack Overflow
or by user1746617
Published on 2012-10-15T09:34:45Z
Indexed on
2012/10/15
9:36 UTC
Read the original article
Hit count: 185
sha256
hey can u be more specific on how to convert to bin to hex.
bool HashStatus::calculate_digest_value(char * path,unsigned char * output)
{
FILE* file = fopen(path, "rb");
if(!file) {
g_message("SignatureValidator::VerifyReferences,file not opened");
return -1;
}
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
const int bufSize = 32768;
unsigned char* buffer = malloc(bufSize);
int bytesRead = 0;
if(!buffer) return NULL;
while((bytesRead = fread(buffer, 1, bufSize, file)))
{
g_message("calculate digest value,verify.cpp::%s",buffer);
SHA256_Update(&sha256, buffer, bytesRead);
}
SHA256_Final(hash, &sha256);
g_message("verify.cpp,after final");
sha256_hash_string(hash, output);
g_message("verify.cpp,after sha256_hash_string %s",hash);
fclose(file);
free(buffer);
return true;
}
this is my code to convert file data into hash using sha256 openssl function
o/p is :1d54e12333988471354907a760b9cde861423615bb5255ee837e3b27b32366 but actual o/p is:HVThAjM5iEcTVJB6dgC5zehhQjYVu1JV7oN+OyezI2Y=
can you guys please help me with whatz wrong with this code,ASAP
and i'm new to this please guide me step by step and in detail..
© Stack Overflow or respective owner