MD5 hashes from string don't match up
I need to convert a password to an MD5 hash and compare it to the MD5 hash
I get from the webservice. If these two match, the user can login.
Let's say the user's password is 'cat'. If I make a hash out of that I get
d077f244def8a70e5ea758bd8352fcd8. This equals the hash I receive from the
webservice. Now I know the code for creating the MD5 is correct.
However, when the password is 'çàt', I get this hash:
727f8e931135b44b37eb147c8a7a56af. The webservice gives me back this hash:
f571ca52b4e3c5a6f49675deaea89cac.
So that's the problem. For some reason these 2 hashes of the same word are
different, didn't know such a thing was even possible. It only happens
when there's an accent or some other weird character in the password
though, so I think it has something to do with encoding.
I tried using NSISOLatin1StringEncoding like this:
NSString *string = [NSString stringWithFormat:@"çàt"];
char converted[([string length] + 1)];
[string getCString:converted maxLength:([string length] + 1) encoding:
NSISOLatin1StringEncoding];
NSString *converted_str = [NSString stringWithCString:converted
encoding:NSISOLatin1StringEncoding];
Found here: How to convert utf8 encoding to iso 8859-1 encoding?
But that doesn't give me the correct hash either.
I tried all the possible NSString encodings but none of em returned the
right hash.
So what can I do about this. Is there something wrong with the code for
converting the encoding? Or maybe it doesn't have anything to do with
encoding (since trying other encodings isn't working)?
No comments:
Post a Comment