iphone - Objective-C 中的 "implicit declaration of function"错误

标签 iphone objective-c md5

我想将一个短字符串转换为 md5 哈希,我找到了几篇关于它的帖子,但没有人工作。 这是我找到的最简单的例子。我有这个错误

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

更新 我添加了#import,当我像这样调用方法时它工作正常:

[self md5:@"admin"];

,我得到了正确的 md5 哈希值。但是当我这样做的时候

 [self md5:userId];

我得到一个错误,

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

最佳答案

因为没有看到CC_MD5的声明。

在你的项目中包含安全框架

#import <CommonCrypto/CommonDigest.h>

关于iphone - Objective-C 中的 "implicit declaration of function"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8497628/

相关文章:

iphone - SpeakHere 示例无法播放从互联网加载的声音

ios - fetchRequest 返回空数组

objective-c - 防止用户注销或关机

gwt - GWT中的post token是如何生成的?

php - 根据包含 APR1-MD5 密码哈希值的文件检查输入的密码

iphone - CorePlot 是否支持图表的缩放和平移?

iPhone:根据位置排序

iphone - 根据用户事件注销

ios - 鸟舍整合问题

web-services - 使用file.managed在Salt中下载文件