0

我在应用商店中有一个应用,我用它来散列通行证:

    //salt the password
NSString* saltedPassword = [NSString stringWithFormat:@"%@%@", fldPassword.text, kSalt];

//prepare the hashed storage
NSString* hashedPassword = nil;
unsigned char hashedPasswordData[CC_SHA1_DIGEST_LENGTH];
//hash the pass
NSData *data = [saltedPassword dataUsingEncoding: NSUTF8StringEncoding];
if (CC_SHA1([data bytes], [data length], hashedPasswordData)) {
    hashedPassword = [[NSString alloc] initWithBytes:hashedPasswordData length:sizeof(hashedPasswordData) encoding:NSASCIIStringEncoding];

我在数据库中的密码是 Vîÿ¿ Ø2(&Zw6

我的问题是我找不到做同样事情的 php 函数,所以用户可以在那里重置 pass 。

我可以在 Xcode 中这样做:

 NSString *hashkey = <your data here>;
 // PHP uses ASCII encoding, not UTF
 const char *s = [hashkey cStringUsingEncoding:NSASCIIStringEncoding];
 NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];

 // This is the destination
uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
// This one function does an unkeyed SHA1 hash of your hash data
CC_SHA1(keyData.bytes, keyData.length, digest);

// Now convert to NSData structure to make it usable again
NSData *out = [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
// description converts to hex but puts <> around it and spaces every 4 bytes
NSString *hash = [out description];
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
// hash is now a string with just the 40char hash value in it

这给了我一个代码thats = to sha1() php中的函数,但如果我这样做,我必须重置所有当前用户传递并将其邮寄给他们:-/

4

0 回答 0