I'm quite puzzled. I'm using this method in my app, and when I pass in two different strings, it can return me the same result.
But when I copy this method to another app, my results are normal - I get back two totally different results for both the strings.
+(NSString *) returnMD5HashOfString:(NSString*)aString
{
// Create byte array of unsigned chars
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
// Create 16 byte MD5 hash value, store in buffer
CC_MD5(aString, aString.length, md5Buffer);
// Convert MD5 value in the buffer to NSString of hex values
开发者_开发问答 NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x",md5Buffer[i]];
return output;
}
CC_MD5 does not expect a string, it expects a char pointer.
精彩评论