here is how you can generate base64 HMAC-SHA1 .
You need to add Base64.h and Base64.m to your project. You can get it here .
If you use ARC, it will show some errors in Base64.m. Find strings similar to this
return [[[self alloc] initWithBase64String:base64String] autorelease];
you need to delete the auto-ad section. The end result should look like this:
return [[self alloc] initWithBase64String:base64String];
Now in your general project, import "Base64.h" and the following code
#import "Base64.h" #include <CommonCrypto/CommonDigest.h> #include <CommonCrypto/CommonHMAC.h> - (NSString *)hmacsha1:(NSString *)data secret:(NSString *)key { const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; NSString *hash = [HMAC base64String]; return hash; }
FROM
NSLog(@"Hash: %@", hash);
you will get something similar to this:
ghVEjPvxwLN1lBi0Jh46VpIchOc=
Zsivics Sanel Aug 28 2018-12-12T00: 00Z
source share