Last active
August 12, 2018 18:23
-
-
Save nishabe/7f2dce33772e81ff98fe77287ce7cd17 to your computer and use it in GitHub Desktop.
OBJC: HMAC creation - Pass Key and Data as String
This file contains hidden or 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*)generateHMACwith :(NSString* )key :(NSString*)data{ | |
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; | |
const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding]; | |
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; | |
CCHmac(kCCHmacAlgSHA256, | |
cKey, | |
strlen(cKey), | |
cData, | |
strlen(cData), | |
cHMAC); | |
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC | |
length:sizeof(cHMAC)]; | |
NSString *hash = [HMAC base64EncodedStringWithOptions:0]; | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment