Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Last active December 14, 2015 09:29
Show Gist options
  • Select an option

  • Save jcromartie/5065234 to your computer and use it in GitHub Desktop.

Select an option

Save jcromartie/5065234 to your computer and use it in GitHub Desktop.
@implementation NSString (JPCSHA1)
- (NSString *)jpc_SHA1String
{
unsigned char md[CC_SHA1_DIGEST_LENGTH];
NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
CC_SHA1([data bytes], [data length], md);
NSMutableString *result = [NSMutableString string];
for (int ii = 0; ii < CC_SHA1_DIGEST_LENGTH; ii++) {
[result appendFormat:@"%02x", md[ii]];
}
return result;
}
@end
// usage [@"testsha1" jpc_SHA1String] => outputs "1dee4b1affb249bc74c20379e60166366b71394f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment