First place this line after the UIKit #import of the .h file:
|
1 |
#import <CommonCrypto/CommonDigest.h> |
And then add this function to your .m file:
|
1 2 3 4 5 6 7 8 9 10 11 |
- (NSString*)md5:(NSString*)input { const char* str = [input UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, strlen(str), result); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2]; for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@"%02x",result[i]]; } return ret; } |
Use it like:
|
1 |
NSString *passwordHash = [self md5: [password text]]; |