I tried to ask a follow-up question on this topic with example code on how to generate rsa-keys which did not work for me, but it got deleted by moderator for some reason. So I'm going to try agin with posting a new question.
My problem with that answer is that Xcode tells me that "kSecPrivateKeyAttrs" and "kSecPublicKeyAttrs" identifiers is not declared. These identifiers are mentioned in apple developer docs, but they does not seem to exist in Secure framework.
I'm using Xcode 4.5 and OS X SDK 10.8.
appreciate any help i can get, I'm fairly new att OC-programming. If i get this to work, I Would also like to know how to get pubkey and privkey as NSString or NSData.
Thank you
EDIT: I still have problems with this, surely there's someone else out there with the same problem that have fixed it and can point me in the right direction?
EDIT2 As I Said, i was trying out the code from the link i posted, but here is the full code anyways:
Keypair.h
#import <Security/Security.h>
@interface Keypair
{
SecKeyRef publicKey;
SecKeyRef privateKey;
NSData *publicTag;
NSData *privateTag;
}
- (void)generateKeyPair:(NSUInteger)keySize;
@end
Keypair.m
#import "Keypair.h"
@implementation Keypair
static const UInt8 publicKeyIdentifier[] = "com.XXXXXXX.publickey\0";
static const UInt8 privateKeyIdentifier[] = "com.XXXXXXX.privatekey\0";
+ (void)generateKeyPair:(NSUInteger)keySize {
OSStatus sanityCheck = noErr;
SecKeyRef publicKey = NULL;
SecKeyRef privateKey = NULL;
NSData *publicTag;
NSData *privateTag;
// Container dictionaries.
NSMutableDictionary * privateKeyAttr = [[NSMutableDictionary alloc] init];
NSMutableDictionary * publicKeyAttr = [[NSMutableDictionary alloc] init];
NSMutableDictionary * keyPairAttr = [[NSMutableDictionary alloc] init];
// Set top level dictionary for the keypair.
[keyPairAttr setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
[keyPairAttr setObject:[NSNumber numberWithUnsignedInteger:keySize] forKey:(__bridge id)kSecAttrKeySizeInBits];
[keyPairAttr setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecAttrIsPermanent];
// Set the private key dictionary.
[privateKeyAttr setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecAttrIsPermanent];
[privateKeyAttr setObject:privateTag forKey:(__bridge id)kSecAttrApplicationTag];
// See SecKey.h to set other flag values.
// Set the public key dictionary.
[publicKeyAttr setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecAttrIsPermanent];
[publicKeyAttr setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag];
// See SecKey.h to set other flag values.
// Set attributes to top level dictionary.
[keyPairAttr setObject:privateKeyAttr forKey:(id)kSecPrivateKeyAttrs];
[keyPairAttr setObject:publicKeyAttr forKey:(id)kSecPublicKeyAttrs];
// SecKeyGeneratePair returns the SecKeyRefs just for educational purposes.
sanityCheck = SecKeyGeneratePair((__bridge CFDictionaryRef)keyPairAttr, &publicKey, &privateKey);
if(sanityCheck == noErr && publicKey != NULL && privateKey != NULL)
{
NSLog(@"Successful");
}
}
@end