您一定会认为将此问题标记为重复。但是,请看看这个问题,无论如何可以帮助我。我无法在iOS中使用CCHmac
我想在iOS中生成含盐的SHA512。我发现下面的代码片段来实现这一点,但我发现CCHmac()函数是为mac。
-(NSString *)hashString:(NSString *)data withSalt:(NSString *)salt
{
const char *cKey = [salt cStringUsingEncoding:NSUTF8StringEncoding];
const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSString *hash;
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", cHMAC[i]];
hash = output;
return hash;
}
如果我使用CC_SHA512()功能,那么我将如何使用盐字符串?我非常渴望得到答案。
感谢您的建议和建议。
谢谢!
哈希和HMACs不是一回事吗?如果你想要使用类似'CCKeyDerivationPBKDF'的字符串的哈希散列。请参阅[this](http://security.stackexchange.com/questions/29951/salted-hashes-vs-hmac)了解更多信息。 – Rich
另外'CCHmac'不仅仅是OS X(名字中的mac与它仅仅是Mac(OS X)无关),[这个问题](http://stackoverflow.com/questions/26655999/create-哈希快速使用键和消息)使用它。 – Rich
不要命名字符串参数'data'。 – zaph