• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
MD5 Checksum of a file with CommonDigest.h
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MD5 Checksum of a file with CommonDigest.h


  • Subject: MD5 Checksum of a file with CommonDigest.h
  • From: "Sebastian Pape" <email@hidden>
  • Date: Thu, 20 Nov 2008 23:12:07 +0100

Hi,
I'm trying to get a MD5 Checksum of a file. This is my code:

______________________________

#import <CommonCrypto/CommonDigest.h>

- (NSString*)getMD5ChecksumOfFile:(NSString*)pathOfFile {

const char *cStr = [[NSData dataWithContentsOfFile:pathOfFile] bytes];

unsigned char result[CC_MD5_DIGEST_LENGTH];

CC_MD5(cStr, strlen(cStr), result);

return [NSString
			stringWithFormat:
@"XXXXXXXXXXXXXXXX",
			result[0], result[1],
			result[2], result[3],
			result[4], result[5],
			result[6], result[7],
			result[8], result[9],
			result[10], result[11],
			result[12], result[13],
			result[14], result[15]];

__________________________
When I try to checksum a file I get a different checksum, than on the
command line using MD5.

My result: D41D8CD98F00B204E9800998ECF8427E

command line result ("md5 test.txt"): a3801c714957c21382d7fe07e0b29aa8

Can anybody tell me, why my code might be wrong. Or am I just doing
something wrong, when verifying my result against the command line
result?

Thankyou,
Sebastian.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: MD5 Checksum of a file with CommonDigest.h
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: Is -rangeOfUserTextChange: supposed to wipe out marked text/diacritical marks?
  • Next by Date: Re: MD5 Checksum of a file with CommonDigest.h
  • Previous by thread: Re: Cocoa-dev Digest, Vol 5, Issue 1990
  • Next by thread: Re: MD5 Checksum of a file with CommonDigest.h
  • Index(es):
    • Date
    • Thread