1 #import "ITCategory-NSData.h"
2 #import <openssl/md5.h>
3 #import <openssl/sha.h>
5 @implementation NSData (ITFoundationCategory)
7 - (NSString *)hexadecimalRepresentation {
8 int dataLength = [self length];
9 int stringLength = dataLength * 2;
11 char *dataBytes = [self bytes];
12 char hexString[stringLength];
15 for (i=0; i < dataLength; i++) {
16 sprintf(hexString + (i * 2), "%02x", dataBytes[i]);
19 return [NSString stringWithCString:hexString length:stringLength];
24 unsigned char digest[length];
25 MD5([self bytes], [self length], digest);
26 return [NSData dataWithBytes:&digest length:length];
31 unsigned char digest[length];
32 SHA1([self bytes], [self length], digest);
33 return [NSData dataWithBytes:&digest length:length];