kSecRandomDefault 未找到?

发布于 2024-12-22 20:19:59 字数 529 浏览 5 评论 0原文

我在 Mac OS 10.7 上使用 CommonCrypto 进行加密。这个框架不是内置的吗?当我生成随机数据时:

+ (NSData *)randomDataOfLength:(size_t)length {
NSMutableData *data = [NSMutableData dataWithLength:length];

int result = SecRandomCopyBytes(kSecRandomDefault, 
                                length,
                                data.mutableBytes);
NSAssert(result == 0, @"Unable to generate random bytes: %d",
         errno);

return data;

}

我收到错误使用未声明的标识符 kSecRandomDefault,我相信它是在 CommonCrypto 中声明的。

谢谢,非常感谢所有帮助。

I am using CommonCrypto for encryption on Mac OS 10.7. Isn't this framework built in? When I am generating random data:

+ (NSData *)randomDataOfLength:(size_t)length {
NSMutableData *data = [NSMutableData dataWithLength:length];

int result = SecRandomCopyBytes(kSecRandomDefault, 
                                length,
                                data.mutableBytes);
NSAssert(result == 0, @"Unable to generate random bytes: %d",
         errno);

return data;

}

I get the error use of undeclared identifier kSecRandomDefault, which I believe is declared in CommonCrypto.

Thanks, all help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中性美 2024-12-29 20:19:59

它在 SecRandom.h 中定义。确保您已在项目中包含 Security 框架并添加适当的头文件。它不包含在框架默认标头中(我不确定这是一个过度站点还是故意的)。因此,将以下导入添加到您的实现文件中:

#import <Security/SecRandom.h>

It's defined in SecRandom.h. Make sure you've included the Security framework in your project and add the appropriate header file. It's not included with the framework default headers (I'm not sure if that's an over site or intentional). So, add the following import to your implementation file:

#import <Security/SecRandom.h>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文