Created
April 25, 2014 01:23
-
-
Save Nunocky/11275060 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 "NSString+MD5.h" | |
@implementation NSString(MD5) | |
-(NSString*)md5sum; | |
{ | |
NSTask *task = [[NSTask alloc] init]; | |
[task setLaunchPath:@"/sbin/md5"]; | |
[task setArguments:@[@"-q", self]]; | |
NSPipe *outPipe = [[NSPipe alloc] init]; | |
[task setStandardOutput:outPipe]; | |
[task launch]; | |
NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile]; | |
[task waitUntilExit]; | |
if ([task terminationStatus] != 0) { | |
NSLog(@"NSString + MD5 : error"); | |
return nil; | |
} | |
NSString *str = [[NSString alloc] initWithData:data | |
encoding:NSUTF8StringEncoding]; | |
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; | |
return str; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment