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;
Because the declaration of CC_MD5 has not been seen.
Include the security framework in your project and
#import <CommonCrypto/CommonDigest.h>
您需要在定义了MD5函数的类顶部包括Crypto库中的CommonDigest Header文件,并包括安全框架
#import <CommonCrypto/CommonDigest.h>
您是否正在导入定义CC_MD5的正确接口?
#import "CommonDigest.h"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.