Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <CommonCrypto/CommonHMAC.h>
- NSString *hashkey = @"Some text to hash";
- // PHP uses ASCII encoding, not UTF
- const char *s = [hashkey cStringUsingEncoding:NSASCIIStringEncoding];
- NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];
- // This is the destination
- uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
- // This one function does an unkeyed SHA1 hash of your hash data
- CC_SHA1(keyData.bytes, keyData.length, digest);
- // Now convert to NSData structure to make it usable again
- NSData *out = [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
- // description converts to hex but puts <> around it and spaces every 4 bytes
- NSString *hash = [out description];
- hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
- hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
- hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
- NSLog(@"hash: %@", hash);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement