Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created May 2, 2012 17:45
Show Gist options
  • Save kristopherjohnson/2578620 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/2578620 to your computer and use it in GitHub Desktop.
Generate SHA1 hash from UTF8 encoding of a string
- (NSData *)SHA1HashOfUTF8String {
const char *UTF8 = [self UTF8String];
size_t UTF8Length = strlen(UTF8);
unsigned char hashedUTF8[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(UTF8, UTF8Length, hashedUTF8);
return [NSData dataWithBytes:hashedUTF8 length:sizeof(hashedUTF8)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment