17

How can I count CRC (32 or 64) of an NSData object in Objective-C?

Thanks in advance!

Knodel
  • 4,359
  • 8
  • 42
  • 66

2 Answers2

42

Use crc32() function from zlib library:

#import <zlib.h>

NSData *data;

// ...

unsigned long result = crc32(0, data.bytes, data.length);
NSLog(@"CRC32: %lu", result);

Make sure to link libz library with your project:

enter image description here

5lava
  • 1,168
  • 11
  • 12
1

From iOS11 use this:

unsigned long result = crc32_z(0, data.bytes, data.length);
AlexeyVMP
  • 2,386
  • 3
  • 24
  • 31