我正在实现将在 IOS 上运行的移动应用程序 sha-512 功能,该功能在包括 Safari 在内的所有浏览器上都可以正常工作。
我正在使用 IOS 模拟器测试我的应用程序。
我的应用程序从一页/单击中调用 sha-512 函数三次。问题是,第一次调用 sha-512 函数会产生正确的结果,但在第二次和第三次调用时会产生错误的结果。
提前致谢
我正在实现将在 IOS 上运行的移动应用程序 sha-512 功能,该功能在包括 Safari 在内的所有浏览器上都可以正常工作。
我正在使用 IOS 模拟器测试我的应用程序。
我的应用程序从一页/单击中调用 sha-512 函数三次。问题是,第一次调用 sha-512 函数会产生正确的结果,但在第二次和第三次调用时会产生错误的结果。
提前致谢
这是我的代码
//Creating Hash Value
NSString *hashkey = [NSString stringWithFormat:@"data"];
// PHP uses ASCII encoding, not UTF
NSLog(@"hashkey : %@",hashkey);
const char *s = [hashkey cStringUsingEncoding:NSASCIIStringEncoding];
NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];
// This is the destination SHA512_Final
uint8_t digest[CC_SHA512_DIGEST_LENGTH] = {0};
// This one function does an unkeyed SHA1 hash of your hash data
CC_SHA512(keyData.bytes, keyData.length, digest);
// Now convert to NSData structure to make it usable again
NSData *out = [NSData dataWithBytes:digest length:CC_SHA512_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:@""];
希望对你有帮助。。