Get CRC checksum of an NSData in Objective-C

2019-01-14 02:53发布

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

Thanks in advance!

3条回答
混吃等死
2楼-- · 2019-01-14 03:33

From iOS11 use this:

unsigned long result = crc32_z(0, data.bytes, data.length);
查看更多
forever°为你锁心
3楼-- · 2019-01-14 03:48

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

查看更多
登录 后发表回答