title: SHA512 with salt for iOS
body: <p>Hi is there anyone with a working SHA512 iOS implementation? The code doesn't seem to generate the same one I have on php.</p>
  
  <pre><code>&lt;?php
  
  $code =  hash("SHA512", '123' . '123' );
  echo $code;
  ?&gt;
  </code></pre>
  
  <p><strong>Output:</strong>
  263fec58861449aacc1c328a4aff64aff4c62df4a2d50b3f207fa89b6e242c9aa778e7a8baeffef85b6ca6d2e7dc16ff0a760d59c13c238f6bcdc32f8ce9cc62</p>
  
  <pre><code>- (NSString *) sha512:(NSString *) input withSalt: (NSString *) salt {
  
  
  const char *cKey  = [salt cStringUsingEncoding:NSUTF8StringEncoding];
  const char *data = [input cStringUsingEncoding:NSUTF8StringEncoding];
  unsigned char digest[CC_SHA512_DIGEST_LENGTH];
  CCHmac(kCCHmacAlgSHA512, cKey, strlen(cKey), data, strlen(data), digest);
  
  NSString *hash;
  
  NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
  
  for(int i = 0; i &lt; CC_SHA512_DIGEST_LENGTH; i++)
      [output appendFormat:@"%02x", digest[i]];
  hash = output;
  return hash;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>[self sha512:@"123" withSalt:@"123"];
  </code></pre>
  
  <p><strong>Output:</strong>
  3cafe40f92be6ac77d2792b4b267c2da11e3f3087b93bb19c6c5133786984b44</p>