我正在尝试为我的应用编写密码加密函数,参考这篇文章。
我编写了一个运行
这很完美,但当我尝试实现下一部分时,一切都出错了。
我可以开始写
但是一旦我输入分号";",它就会标记一个错误,显示“CCKeyDerivationPBKDF没有匹配的函数调用”,而且它不会构建或做任何事情。
我已经导入了CommonCrypto/CommonKeyDerivation.h和CommonCrypto/CommonCryptor.h,因为这两个都是必要的枚举名称。
我编写了一个运行
CCCalibratePBKDF
函数并输出轮数的函数。const uint32_t oneSecond = 1000;
uint rounds = CCCalibratePBKDF(kCCPBKDF2,
predictedPasswordLength,
predictedSaltLength,
kCCPRFHmacAlgSHA256,
kCCKeySizeAES128,
oneSecond);
这很完美,但当我尝试实现下一部分时,一切都出错了。
我可以开始写
CCKeyDerivationPBKDF
函数调用,它会自动完成函数和所有参数。填写参数时,所有参数也会自动完成。- (NSData *)authenticationDataForPassword: (NSString *)password salt: (NSData *)salt rounds: (uint) rounds
{
const NSString *plainData = @"Fuzzy Aliens";
uint8_t key[kCCKeySizeAES128] = {0};
int keyDerivationResult = CCKeyDerivationPBKDF(kCCPBKDF2,
[password UTF8String],
[password lengthOfBytesUsingEncoding: NSUTF8StringEncoding],
[salt bytes],
[salt length],
kCCPRFHmacAlgSHA256,
rounds,
key,
kCCKeySizeAES128);
if (keyDerivationResult == kCCParamError) {
//you shouldn't get here with the parameters as above
return nil;
}
uint8_t hmac[CC_SHA256_DIGEST_LENGTH] = {0};
CCHmac(kCCHmacAlgSHA256,
key,
kCCKeySizeAES128,
[plainData UTF8String],
[plainData lengthOfBytesUsingEncoding: NSUTF8StringEncoding],
hmac);
NSData *hmacData = [NSData dataWithBytes: hmac length: CC_SHA256_DIGEST_LENGTH];
return hmacData;
}
但是一旦我输入分号";",它就会标记一个错误,显示“CCKeyDerivationPBKDF没有匹配的函数调用”,而且它不会构建或做任何事情。
我已经导入了CommonCrypto/CommonKeyDerivation.h和CommonCrypto/CommonCryptor.h,因为这两个都是必要的枚举名称。