Created
March 23, 2013 13:36
-
-
Save yangboz/77fffef6b6d4fe16b144 to your computer and use it in GitHub Desktop.
Hash-based message authentication code Ref:http://en.wikipedia.org/wiki/HMAC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString*) HMACWithSecret:(NSString*)secret andData:(NSString *)data | |
{ | |
CCHmacContext ctx; | |
const char *key = [secret UTF8String]; | |
const char *str = [data UTF8String]; | |
unsigned char mac[CC_SHA256_DIGEST_LENGTH]; | |
char hexmac[CC_SHA256_DIGEST_LENGTH]; | |
char *p; | |
CCHmacInit( &ctx, kCCHmacAlgSHA256, key, strlen( key )); | |
CCHmacUpdate( &ctx, str, strlen(str) ); | |
CCHmacFinal( &ctx, mac ); | |
p = hexmac; | |
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++ ) { | |
snprintf( p, 3, "%02x", mac[ i ] ); | |
p += 2; | |
} | |
return [NSString stringWithUTF8String:hexmac]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2013-11-26 17:16:07.704 ChatBotsMessager[547:60b] API request response str:{"success":0,"errorType":"Missing parameter","errorMessage":"The hash parameter must be passed in the url."}