CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85

    MD5 checksum help!

    I'm trying to use MD5 to calculate a checksum of a file an object was created from, and then store the file's checksum in the object for comparison later... and I'm having a problem that may be the way I'm storing it. I'm storing the checksum like this: unsigned char CheckSum[16] but I'm wondering id it's better to store it as 4 Ints? Anyone have any idea using MD5?
    Last edited by Thresher; December 17th, 2003 at 03:36 PM.

  2. #2
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201
    I think using "unsigned char*" as pointer to buffer of 128 bit it's ok. But what is your problem?

  3. #3
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85
    Well.... I was storing the checksum as an unsigned char checksum[16] and had a few problems... like I tried to copy it using strcpy (w/o casting it.. &#$%#) and I was wondering if I should just store is as int1, int2 int3 int4 and not as a char[16]. Anyway I got the unsigned char[16] to work ... it just took this noob forever! When you say just have a "pointer to a 128 bit buffer"... are you suggusting a whole different checksum object? I thought of this but I didn't have alot of time left to get this done.

  4. #4
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201
    You can not use strcpy to copy the hash (checksum).
    Always use memcpy, because strcpy copies the characters until it finds some \0 character and your checksum may contain such characters before strcpy reaches the end of your checksum.
    So for copying the check sum use following scenario:

    unsigned char CheckSum[16];

    //Retreiving CheckSum
    ...
    memcpy(lpBuffer, CheckSum, 16);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured