this topic에 대한 후속 질문을 예제로 작성하려고 시도했지만 어떤 이유로 작동하지 않는 RSA 키를 생성하는 방법에 대한 예제 코드가 있지만 어떤 이유로 든 운영자가 삭제했습니다. . 그래서 저는 새로운 질문을 게시하면서 agin을 시도 할 것입니다.Objective C Secure.h RSA 키 쌍 생성
내 대답은 Xcode에서 "kSecPrivateKeyAttrs"및 "kSecPublicKeyAttrs"식별자가 선언되지 않았다는 것입니다. 이 식별자는 Apple 개발자 문서에 언급되어 있지만 Secure 프레임 워크에는 존재하지 않습니다.
저는 Xcode 4.5와 OS X SDK 10.8을 사용하고 있습니다.
내가 얻을 수있는 도움을 주시면 고맙겠습니다. 저는 꽤 새로운 att OC 프로그래밍입니다. 이것이 작동하면 NSString 또는 NSData로 pubkey 및 privkey를 얻는 방법을 알고 싶습니다. 나는 여전히이 문제가 반드시 누군가가 그것을 고정하고 올바른 방향으로 날 지점 수있는 동일한 문제를 거기에 다른있다 :
당신에게EDIT 감사?
내가 말했듯이, 내가 여기에 내가 게시 된 링크의 코드를 시도 되었으나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
답변이 삭제되었으므로 포럼이 아닙니다. 코드를 보여주십시오. 당신은 거의 확실하게 헤더 파일을'# import '하지 못하고있다. – trojanfoe
나는 사용하려고하는 전체 코드를 게시했습니다. 빠진 #import를 찾을 수 없습니다. OSX에 뭔가 다른 것이 필요할 것 같은가요? 이것이 IOS와 다른 이유는 알 수 없지만 그렇다면 kSec {Public, Private} KeyAttrs 이외에 다른 것을 제안하십시오. – Dlq
좋아요, 그래서 저는 kSecPublicKeyAttrs를 @ "public"과 @ "private"으로 바꾸는 것으로 간단히 작동합니다. 왜냐하면 어떤 이유로 Security.framework의 Ios 버전에만 존재하기 때문입니다. 이제는 나중에 사용하기 위해 공용 키를 검색하는 것입니다. OT : 왜 애플은 나를 싫어합니까? – Dlq