title: Mac App Store Receipt - Hash not matching. Why?
body: <p>I'm trying to create a Mac application, and be gentle on me as this is my first attempt! Essentially transferring what I've done on iOS to the Mac and it's almost ready to go with one part remaining - App Store verification to prevent people from being able to copy it.</p>
  
  <p>I have receipt verification code running in a couple of my iOS apps and they work find for me (for in-app purchase). With the Mac I simply want to verify the receipt and hope that's enough.   Here is the basis of the code I have created:</p>
  
  <pre><code>char buf[512] = "";
  get_platform_uuid(buf, sizeof(buf));
  
  NSString *uuidString = [NSString stringWithUTF8String:buf];
  NSUUID *myUUID = [[NSUUID UUID] initWithUUIDString:uuidString];
  
  unsigned char uuidBytes[16];
  [myUUID getUUIDBytes:uuidBytes];
  
  NSMutableData *input = [NSMutableData data];
  [input appendBytes:uuidBytes length:16];
  [input appendData:[receipt objectForKey:kReceiptOpaqueValue]];
  [input appendData:[receipt objectForKey:kReceiptBundleIdentifierData]];
  
  NSMutableData *hash = [NSMutableData dataWithLength:SHA_DIGEST_LENGTH];
  SHA1([input bytes], [input length], [hash mutableBytes]);
  
  NSLog(@"kReceiptHash: %@", [receipt objectForKey:kReceiptHash]);
  NSLog(@"hash: %@", hash);
  </code></pre>
  
  <p>The last two NSLog commands are just so that I can log this during debug, but the hash values would be compared.   This is where I know the two are incorrect.   "get_platform_uuid" is a function I've found for getting the UUID for the Mac and it seems to work fine.</p>
  
  <p>I've taken the entire "input" variable and plugged the information in to it and ran it on iOS, and I've done the same from the iOS device and run it on the Mac.   In both cases the calculated Hash is the same; I think the calculation is fine.</p>
  
  <p>But on the Mac it is still different from the receipt hash.   The iOS calculation and receipt hash matches for that app.</p>
  
  <p>I've set up the App on iTunes Connect, it seems to pick up the right bundle identifier.   I have logged out of the App Store on the Mac.   I copy the App out from where Xcode builds the app to a different directory to run it.   It then asks me to log in, which I do with a test account.   Then repeatedly tries to rerun the app and exits (I copy it back to the debug folder and this breaks that rerunning cycle).</p>
  
  <p>I've got the certificates set up for development and distribution for Mac set up in the Apple Developer site but I'm sure it's something that I've not got right with App permissions or how I'm running the app.   But what I just can't figure out (and I have looked - for a long time!).</p>
  
  <p>I'm sure it's something silly, but as a lone developer my only hope is to ask you what am I doing wrong?</p>
  
  <p>Thanks.</p>