문제

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