您的位置:首页 > 其它

md5加密导入库报错解决

2015-05-29 15:20 239 查看
一,用系统自带的MD5进行加密方法一:- (NSString *)md5HexDigest:(NSString*)input{ const char* str = [input UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, strlen(str), result); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2]; for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@"%02x",result]; } return ret;}方法二:
- (NSString *)md5:(NSString *)str
{
const char *cStr = [str UTF8String];
unsigned char result[16];
CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}

二,导入系统类库:
#import <CommonCrypto/CommonDigest.h>

三,报错:ld: cannot link directly with /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system/libcommonCrypto.dylib. Link against the umbrella framework 'System.framework' instead.

四,解决方案:
删去libcommonCrypto.dylib,用System.framework库中的libSystem.dylib替代。

MD5加密和导入库的解决方案分别来自不同出处的网络资源总结,如有侵权,请联系本博主注明。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  md5加密 类库报错