嗨,有人使用 SHA512 iOS 实现吗?该代码似乎与我在 php 上生成的代码不同。
<?php
$code = hash("SHA512", '123' . '123' );
echo $code;
?>
输出: 263fec58861449aacc1c328a4aff64aff4c62df4a2d50b3f207fa89b6e242c9aa778e7a8baeffef85b6ca6d2e7dc16ff0a760d59c13c238f6bcdc32f8ce9cc62
- (NSString *) sha512:(NSString *) input withSalt: (NSString *) salt {
const char *cKey = [salt cStringUsingEncoding:NSUTF8StringEncoding];
const char *data = [input cStringUsingEncoding:NSUTF8StringEncoding];
unsigned char digest[CC_SHA512_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA512, cKey, strlen(cKey), data, strlen(data), digest);
NSString *hash;
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA512_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
hash = output;
return hash;
}
[self sha512:@"123" withSalt:@"123"];
输出: 3cafe40f92be6ac77d2792b4b267c2da11e3f3087b93bb19c6c5133786984b44