#import <CommonCrypto/CommonDigest.h>
...
NSString *secretCookie = @"lksab8xd7FdjdsD3"; // CHANGE ME!!
NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970];
long timestamp = (long)(timeInterval * 1000);
int hashSize = 20;
unsigned char hashedChars[hashSize];
NSString *strToHash = [NSString stringWithFormat:@"%@%@%d%d", username, secretCookie, score, timestamp];
CC_SHA1([strToHash UTF8String],
[strToHash lengthOfBytesUsingEncoding:NSUTF8StringEncoding], hashedChars);
NSMutableString *hashedString = [[[NSMutableString alloc] init] autorelease];
for (int i=0; i<hashSize; i++) {
[hashedString appendFormat:@"%02x", hashedChars[i]];
}
$secretCookie = "lksab8xd7FdjdsD3"; // Same as above
$hash1 = sha1($username.$secretCookie.$score.$timestamp);
if ($hash != $hash1) {
die("Hashes do not match!");
}
I almost second mpatric's post (it's missing one piece). This is similar to the way I do high scores. It has 3 weaknesses: cracking the encryption itself (very hard), disassemblying the program from a jailbroken iphone and extracting the hash secret (very hard), and somebody resubmitting the same high score thus filling up the top 10 with the same name and score (very easy).
To fix the 3rd issue, submit a timestamp (with the timestamp included in the hash). If you see 2 of the same timestamp, drop the second request.