Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"implicit declaration of function" error in Objective-C

i want to convert a short string to md5 hash , I found several post about it but noone worked. it's the simplest example that I found . i have this error

implicit declaration of function CC_MD5 is invalid in C99

- (NSString *) md5:(NSString *) input
{
 const char *cStr = [input UTF8String];
 unsigned char digest[16];
 CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call

 NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

 for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
 [output appendFormat:@"%02x", digest[i]];

 return  output;
 }

UPDATE i added #import , it work fine when i call the method like this :

[self md5:@"admin"];

, i get the right md5 hash. But when i do this

 [self md5:userId];

i get an error ,

[NSDecimalNumber UTF8String]: unrecognized selector sent to instance 0x4d3e280 But userId is not decimal , he contain facebook id , but it's declared as NSString

NSString *userId;
@property(retain,nonatomic) NSString *userId;
like image 355
user567 Avatar asked Dec 13 '11 23:12

user567


2 Answers

Because the declaration of CC_MD5 has not been seen.

Include the security framework in your project and

#import <CommonCrypto/CommonDigest.h>
like image 169
zaph Avatar answered Oct 12 '22 04:10

zaph


You need to include the CommonDigest Header file from the Crypto library at the top of your class where the MD5 function is defined as well as include the Security Framework

#import <CommonCrypto/CommonDigest.h>
like image 26
Suhail Patel Avatar answered Oct 12 '22 04:10

Suhail Patel