Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Objective-C MD5 NSString

I have found this md5 function here: http://www.makebetterthings.com/iphone/how-to-get-md5-and-sha1-in-objective-c-ios-sdk/

- (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;

}

I have the signature in my header file like this:

- (NSString *) md5:(NSString *) input;

There is no errors showing up in xCode, except where i try to use the function.

NSString *credentials = [md5 @"test"];

I get the message: Use of undeclared identifier 'md5'

How do i use this function?

like image 567
user1359448 Avatar asked Mar 13 '13 18:03

user1359448


1 Answers

You need to use:

NSString *credentials = [self md5:@"test"]; //[md5 @"test"];

If you are calling this method from the class that has method md5:

like image 126
Anoop Vaidya Avatar answered Oct 15 '22 14:10

Anoop Vaidya