Created
April 29, 2015 16:42
-
-
Save Tantas/f0d0ebecbc251f99db58 to your computer and use it in GitHub Desktop.
Objective-C MD5 C Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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