我正在转换我的应用程序在64位系统上工作,我一直试图正确使用内置的CC_SHA1方法.
我收到警告:
Implicit conversion loses integer precision: ‘NSUInteger’ (aka ‘unsigned long’) to ‘CC_LONG’ (aka ‘unsigned int’)
尝试在CC_SHA1方法中传递:data.length.
data.length是NSUInteger
CC_SHA1方法定义是:
extern unsigned char *CC_SHA1(const void *data,CC_LONG len,unsigned char *md)
其中CC_LONG是32位无符号整数.
如何更改它以使用CC_LONG64?
typedef uint64_t CC_LONG64;
这是我得到上述警告的转换方法:
+(NSString*)sha1:(NSString*)input { const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding]; NSData *data = [NSData dataWithBytes:cstr length:input.length]; uint8_t digest[CC_SHA1_DIGEST_LENGTH]; CC_SHA1(data.bytes,data.length,digest); NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; for(NSInteger i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) [output appendFormat:@"%02x",digest[i]]; return output; }