I am trying to replicate the Hmac generation behavior from my iOS app using SHA-512 algorithm referring to this link Objective-C sample code for HMAC-SHA1.
For this
HMAC takes a data key and a key and data parameters which are bytes and returns bytes of a length determined by the hash function specified.
Example:
+ (NSData *)doHmacSha512:(NSData *)dataIn
key:(NSData *)key
{
NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA512_DIGEST_LENGTH];
CCHmac( kCCHmacAlgSHA512,
key.bytes,
key.length,
dataIn.bytes,
dataIn.length,
macOut.mutableBytes);
return macOut;
}
Test:
NSData *keyData = [@"MyTestKey" dataUsingEncoding:NSASCIIStringEncoding];
NSData *data = [@"Now is the time for all good computers to come to the aid of their masters." dataUsingEncoding:NSASCIIStringEncoding];
NSData *hamcData = [Crypto doHmacSha512:data key:keyData]; // Where "Crypto" is the class "doHmacSha512" is defined in.