I am trying to generate an RSA key pair and retrieve the key bytes on OSX. I tried using the technique illustrated by the CryptoExercise sample code for iOS. Everything seems to work, except I always get back only 96 bytes when I try to retrieve the key bytes, regardless of the key size. Here is the code I am using:
CFMutableDictionaryRef query;
query = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(query,kSecClass,kSecClassKey);
CFDictionarySetValue(query,kSecAttrKeyType,kSecAttrKeyTypeRSA);
CFDictionarySetValue(query,kSecAttrApplicationTag,publicTag);
CFDictionarySetValue(query,kSecReturnData,kCFBooleanTrue);
CFDictionarySetValue(query,kSecReturnAttributes,kCFBooleanTrue);
CFDictionaryRef attr;
status = SecItemCopyMatching(query, (CFTypeRef *)&attr);
The dictionary attributes show the correct property for the key, but the "v_Data" has only 96 bytes. Likewise, if I omit the kSecReturnAttributes and just request kSecReturnData. The same code works correctly on iOS, returning the key length + 12 bytes (DER format).
Any trick to make this work on OSX? I guess I can use OpenSSL, which I need anyway for Linux server side. But I was hoping to have iOS compatible code running on OSX for development.