No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
manpreet
Best Answer
2 years ago
I'm using Microsoft's CNG Cryptography API's to compute the hash of a file, so far all works fine except that computed hash is wrong comparing to hash computed with external 3rd party program.
I'm not 100% sure but I think the problem is that I read the file into
signed char
array instead of intoBYTE
(unsigned char) array.Bellow code is how I read the file now: (note: I omitted error checking code)
Problem with above code is that data is read into signed char array but crypto functions expect
unsigned char / BYTE
and I'm guessing this is why my computed hash is wrong.Bellow code is what I would like to do but it doesn't work (added comment) since
ifstream::read()
method expectschar
array notunsigned char / BYTE
So my question is: how do I read data as
BYTE
notchar
do I need to useCreateFile
API or is there a way withstd::ifstream
?Maybe there is something else causing bad computed hash, I don't know if so tell me.
EDIT: Below is fully working code to compute the SHA256 hash for given file name, but the hash is bad. (ie. not the same as if done with 3rd party hash utility)