problem with MD5 in simulator and device(ipad)
i used a MD5 algorithm to create unique string/name for a same image..so i tested with simulator vs ipad.
i downloaded one image in Simulator using safari and created MD5 string for that.it working fine in simulator.in simulator its always creating a same string for same image.
then i downloaded the same image in to ipad from the same site/url through safari. and created a MD5 for this. there is a pr开发者_如何转开发oblem.the two MD5 are different.can any one tell me the exact problem.
is simulator and ipad saving same images in a different size when it downloading.
i used the code:
MyExtensions.h
@interface NSData (MyExtensions)
- (NSString*)md5;
@end
MyExtensions.m
#import "MyExtensions.h"
#import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access
@implementation NSData (MyExtensions)
- (NSString*)md5
{
unsigned char result[16];
CC_MD5( self.bytes, self.length, result ); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end
-(NSString *) md5Image:(UIImage *)img {
return [UIImagePNGRepresentation(img) md5];
}
Check the answer to this post for a possible explanation.
As you can see, the CC_MD5 implementation can contain some data type which takes different number of bytes on 32-bit or 64-bit OS. And this could explain the difference you see in hashing on the simulator (Mac OSX) or the device (iOS).
精彩评论