Skip to content

Instantly share code, notes, and snippets.

@Tantas
Created April 29, 2015 16:42
Show Gist options
  • Save Tantas/f0d0ebecbc251f99db58 to your computer and use it in GitHub Desktop.
Save Tantas/f0d0ebecbc251f99db58 to your computer and use it in GitHub Desktop.
Objective-C MD5 C Function
#import <CommonCrypto/CommonHMAC.h>
NSString* md5(NSString *string) {
const char *cStr = [string UTF8String];
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, (unsigned int)strlen(cStr), digest );
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment