According to this site mysql uses:
SHA1(UNHEX(SHA1("this_is_a_random_string")))
To generate its password() hash.
...
I have copied this function, from another StackOverflow post:
- (NSString *)sha1:(NSString *)str {
const char *cStr = [str UTF8String];
unsigned char result[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(cStr, strlen(cStr), result);
NSString *s = [NSString stringWithFormat:
@"%02X%02X%02X%02X%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],
result[16], result[17], result[18], result[19]
];
return s;
}
To generate sh1 hashes. But as the first link says:
the second SHA1() is applied to the binary data returned by the first SHA1() and not to its hex representation. Therefore in SQL I have to UNHEX() it before applying the second SHA1.
So I have to do something like:
NSString * a = [self sha1:@"abc"];
// convert a into binary data.
NSString * b = [self:sha1:a];
But whatever I try I cannot get it to work.
What is the simplest way to do this?