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.

有帮助吗?

解决方案

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top