このトピックについて、私には機能しなかったrsaキーの生成方法に関するサンプルコードを使用してフォローアップの質問をしようとしましたが、何らかの理由でモデレーターによって削除されました。だから私は新しい質問を投稿することから始めようと思います。
その答えに関する私の問題は、Xcodeが「kSecPrivateKeyAttrs」および「kSecPublicKeyAttrs」識別子が宣言されていないことを教えてくれることです。これらの識別子はアップルデベロッパのドキュメントに記載されていますが、セキュアフレームワークには存在しないようです。
Xcode4.5とOSXSDK10.8を使用しています。
私が得ることができるどんな助けにも感謝します、私はかなり新しいattOCプログラミングです。これを機能させる場合は、pubkeyとprivkeyをNSStringまたはNSDataとして取得する方法も知りたいです。
ありがとうございました
編集:私はまだこれに問題があります、確かにそれを修正し、正しい方向に私を向けることができる同じ問題を抱えている誰かがそこにいますか?
EDIT2私が言ったように、私は投稿したリンクからコードを試していましたが、とにかく完全なコードはここにあります:
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