2013-03-13 45 views
8

我發現這個MD5函數在這裏:http://www.makebetterthings.com/iphone/how-to-get-md5-and-sha1-in-objective-c-ios-sdk/的iOS:Objective-C的MD5的NSString

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

} 

我有一個像這樣在我的頭文件中的簽名:

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

沒有顯示出來沒有錯誤在xCode中,除了我嘗試使用該函數。

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

我得到的消息:未聲明的標識符「MD5」

的使用如何使用這個功能呢?

+0

@ H2CO3類的這個方法:這會方便對他來說,有什麼說什麼你的http://計算器.com/questions/13575037/what-are-resources-for-learning-objective-c – 2013-03-13 18:35:12

+0

@ H2CO3:你在這裏看到我的問題http://stackoverflow.com/questions/15392726/does-synchronized-guarantees-for-線程安全的,或者,不 – 2013-03-13 18:35:39

回答

9

您需要使用:

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

如果你撥打的是有方法md5: