Created
March 30, 2009 09:00
-
-
Save ktakayama/87697 to your computer and use it in GitHub Desktop.
This file contains 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 <Foundation/Foundation.h> | |
#import "CommonCrypto/CommonDigest.h" | |
@interface NSString (MD5) | |
- (NSString *) MD5String; | |
@end | |
@implementation NSString (MD5) | |
- (NSString *) MD5String { | |
const char *cStr = [self UTF8String]; | |
unsigned char digest[CC_MD5_DIGEST_LENGTH]; | |
CC_MD5( cStr, strlen(cStr), digest ); | |
char md5string[CC_MD5_DIGEST_LENGTH*2]; | |
int i; | |
for (i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { | |
sprintf(md5string+i*2, "%02X", digest[i]); | |
} | |
return [NSString stringWithCString:md5string length:CC_MD5_DIGEST_LENGTH*2]; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment