iphone - iOS5 上的 CCKeyDerivationPBKDF

标签 iphone objective-c ios security commoncrypto

我正在尝试将密码加密功能写入我的应用程序,遵循 this article .

我编写了一个运行 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,因为这两者对于枚举名称都是必需的。

最佳答案

首先,确保你没有对你的包含路径做任何有趣的事情(特别是,我不推荐@HachiEthan 的解决方案,这只会混淆事情)。一般来说,别管它,特别是不要在其中添加/usr/include之类的东西。确保您已将 Security.framework 添加到您的链接步骤。这是问题的常见原因。

您最需要确定的是您获得的是 iOS 5 Security.framework(而不是 OS X 10.6 或 iOS 4 等其他版本)。但我怀疑您的build设置有问题。

如果您想查看一个框架来完成所有这些以供引用,请查看 RNCryptor .

关于iphone - iOS5 上的 CCKeyDerivationPBKDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11938300/

相关文章:

iphone - 我需要释放返回的 NSError 对象吗?

iphone - 推送通知徽章没有出现?

ios - 如何以编程方式在 iPhone 应用程序中打开 LinkedIn 公司网址?

c++ - iOS - 在 C++ 中获取可写路径

iphone - UIGestureRecognizer 结尾

iphone - 在 UINavigationBar 和 UIViewController 上覆盖 UIView

ios - 使用 TextField 标记和保存数据

ios - CFStream 类是否符合 IPV6 标准?我正在使用 CFStreamCreatePairWithSocketToHost 连接到套接字而不是低级套接字 api

objective-c - 自定义 UITableViewCell NSUnknownKeyException

android - CoreBLuetooth 限制 ios 无法扫描所有蓝牙设备?