user762034
user762034

Reputation:

kSecRandomDefault not found?

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.

Upvotes: 3

Views: 2391

Answers (1)

Jason Coco
Jason Coco

Reputation: 78383

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>

Upvotes: 11

Related Questions