【发布时间】:2009-02-19 13:24:12
【问题描述】:
我正在尝试使用具有以下签名的函数来签署 HTTP 请求:
extern void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLength, unsigned char *outDigest);
这是我写的使用它的方法:
- (NSString *)sign: (NSString *)stringToSign {
NSString *secretKey = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const unsigned char *inText = (unsigned char *)[stringToSign UTF8String];
int inTextLength = [stringToSign length];
unsigned char *inKey = (unsigned char *)[secretKey UTF8String];
const unsigned int inKeyLength = (unsigned int)[secretKey length];
unsigned char *outDigest;
hmac_sha1(inText, inTextLength, inKey, inKeyLength, outDigest);
NSString *output = [NSString stringWithUTF8String:(const char *)outDigest];
return output;
}
问题是我确定这不是我应该进行这种转换的方式,因为在这个 hmac_sha1 函数中我得到了一个 EXC_BAD_ACCESS 异常。
由于我是 Objective-C 的新手并且几乎没有 C 方面的经验(惊讶!)我真的不知道要搜索什么。关于如何开始解决此问题的任何提示?
提前致谢!
顺便说一句,我得到了这个函数的参考here in stackoverflow。
【问题讨论】:
标签: objective-c iphone