Skip to content

Commit 4f32577

Browse files
author
Anthony Somerset
committed
cleaned up NSString+MD5 for char and NSData mismatch
1 parent 52a3474 commit 4f32577

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

NSString+MD5.m

+4-13
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,19 @@ @implementation NSString (MD5)
1515
///////////////////////////////////////////////////////////////////////////////////////////////////
1616
- (NSString*)md5 {
1717
NSData *md5data = [self dataUsingEncoding:NSUTF8StringEncoding];
18-
18+
19+
const char *md5datastring = [md5data bytes];
1920
// Create byte array of unsigned chars
2021
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
2122

2223
// Create 16 byte MD5 hash value, store in buffer
23-
CC_MD5(md5data, strlen(md5data), md5Buffer);
24+
CC_MD5(md5datastring, strlen(md5datastring), md5Buffer);
2425

2526
// Convert MD5 value in the buffer to NSString of hex values
2627
NSMutableString *digestStr = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
2728
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
2829
[digestStr appendFormat:@"%02x",md5Buffer[i]];
29-
//unsigned char *digest = MD5([md5data bytes], [md5data length], NULL);
30-
//
31-
// NSString *digestStr = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
32-
// digest[0], digest[1],
33-
// digest[2], digest[3],
34-
// digest[4], digest[5],
35-
// digest[6], digest[7],
36-
// digest[8], digest[9],
37-
// digest[10], digest[11],
38-
// digest[12], digest[13],
39-
// digest[14], digest[15]];
30+
4031
return digestStr;
4132
}
4233

0 commit comments

Comments
 (0)