2

I am working on an app which needs to send the data on server in MD5 encoded string. In Objective C MD5 string is generated something like:

*68da55b645ef7fef43d4df4910a30a0d* 

where as on PHP side the MD5 string is generated something like:

  *c16a5320fa475530d9583c34fd356ef5*. 

Here both are not generating same so it creates problem.

Below is my code to generate the MD5 string in Objective C.

- (NSString *)md5
{

const char *cStr = [self UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, (int)strlen(cStr), 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]
        ];  
}

In PHP the MD5 string is generated using MD5.min.js This issue rejects my API calls. Any idea how to make it identical? Ideally it should generate the same on both the sides but it is not generating.

Any help would be appreciated!!!

IRAVIPATEL
  • 71
  • 5
  • check this : http://stackoverflow.com/questions/23089465/how-can-i-do-this-same-encrypt-decrypt-php-function-on-ios-with-objective-c – Nitin Gohel May 24 '16 at 13:13
  • Make sure that you are hashing identical strings, no spaces at the end of one and not on the end of the other, etc If the hashes are different, then the strings were different – Mark Baker May 24 '16 at 13:17
  • @NitinGohel I checked it out. But not getting exactly. – IRAVIPATEL May 24 '16 at 13:33
  • @MarkBaker Yes we are hashing identical strings only and there is no space at any end. – IRAVIPATEL May 24 '16 at 13:34
  • That simply cannot be true.... identical strings generate identical hashes – Mark Baker May 24 '16 at 13:35
  • And note that PHP cannot use `MD5.min.js` to generate a hash.... PHP cannot execute javascript files.... do you mean that js is generating one of those hashes? – Mark Baker May 24 '16 at 13:35

0 Answers0