从生成的对密钥中获取OSX中的公钥位

时间:2013-04-07 11:00:22

标签: objective-c macos cocoa encryption cryptography

此方法用于获取iOS中的公钥位。

- (NSData *)getPublicKeyBits {
    OSStatus sanityCheck = noErr;
    NSData * publicKeyBits = nil;

    NSMutableDictionary * queryPublicKey = [[NSMutableDictionary alloc] init];

    // Set the public key query dictionary.
    [queryPublicKey setObject:(id)kSecClassKey forKey:(id)kSecClass];
    [queryPublicKey setObject:publicTag forKey:(id)kSecAttrApplicationTag];
    [queryPublicKey setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType];
    [queryPublicKey setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnData];

    // Get the key bits.
    sanityCheck = SecItemCopyMatching((CFDictionaryRef)queryPublicKey, (CFTypeRef *)&publicKeyBits);

    if (sanityCheck != noErr)
    {
        publicKeyBits = nil;
    }

    [queryPublicKey release];

    return publicKeyBits;
}

但它仅适用于iOS而不适用于OSX,对于OSX我需要使用安全转换。 https://developer.apple.com/library/mac/#documentation/Security/Conceptual/SecTransformPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010801-CH1-SW1

我知道如何生成对公钥/私钥,并为iOS做。

我需要在OSX中使用哪种转换来从公钥获取公钥位?为了获得与iOS中提供的示例相同的效果。

0 个答案:

没有答案