开发者

Wierd behavior from method generating MD5 hash - returns same hash results

开发者 https://www.devze.com 2023-04-11 05:57 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消