7

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;

3 Answers 3

26

Because the declaration of CC_MD5 has not been seen.

Include the security framework in your project and

#import <CommonCrypto/CommonDigest.h>
Sign up to request clarification or add additional context in comments.

Comments

3

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>

Comments

0

Are you importing the right interface that defines CC_MD5?

#import "CommonDigest.h"

2 Comments

I think you probably mean <CommonDigest.h>
It still works though. But if you want to give the full location then, <CommonCrypto/CommonDigest.h> works just as half of SO has mentioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.