I am trying to use a function that has the following signature to sign an HTTP request:
extern void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLength, unsigned char *outDigest);
And this is the method I wrote to use it:
- (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; }
The problem is that I am sure that this is not the way I should do this casting, since inside this hmac_sha1 function I get an EXC_BAD_ACCESS exception.
Since I am new to Objective-C and have no experience in C (surprise!), I really don't know what to look for. Any tips on how I can solve this?
Thanks in advance!
BTW, I got a link for this function https://stackoverflow.com/a/464626/
objective-c iphone
leolobato
source share