//
// MD5.h
// MacEncryptTool
//
// Created by user on 12-1-17.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import<Foundation/Foundation.h>
#import<commoncrypto/CommonDigest.h>
@interface NSString (MyExtensions)
- (NSString *) md5;
@end
//
// MD5.mm
// MacEncryptTool
//
// Created by user on 12-1-17.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import"MD5.h"
@implementation NSString (MyExtensions)
- (NSString *) md5 {
const char *cStr = [selfUTF8String];
unsigned char result[16];
unsigned int cStrLen = (CC_LONG)strlen(cStr);
CC_MD5( cStr, cStrLen, result );
NSMutableString *target = [NSMutableStringstring];
for(int i = 0; i < 16; ++ i) {
[target appendFormat:@"%02x", result[i]];
}
return target;
}
@end