SecItemAdd创建两个身份 [英] SecItemAdd creating two identities

查看:143
本文介绍了SecItemAdd创建两个身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone开发一个需要证书来调用某些服务的应用程序,所以我在我的钥匙串中添加了一个证书:

I'm developing an application for IPhone that needs a certificate to call some services, so I'm adding a certificate to my keychain doing this:

 SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certificadoData);
 NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
 [dictionary setObject:(__bridge id)kSecClassCertificate forKey:(__bridge id)kSecClass];
 [dictionary setObject:(__bridge id)(cert) forKey:(__bridge id<NSCopying>)(kSecValueRef)];
 OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dictionary, NULL);

当我在此代码之前列出所有kSecClassIdentity时,结果为none,在此代码之后, return是两个身份和一个证书。
当我尝试使用身份时,一个正常工作但另一个没有。为什么SecItemAdd为一个kSecClassCertificate创建了两个kSecClassIdentity?我如何识别正确的?

When I list all the kSecClassIdentity before this code, the result is none and, after this code, the return are two identities and one certificate. When I tried to use the identities, one is working correctly but the other don't. Why the SecItemAdd is creating two kSecClassIdentity for one kSecClassCertificate? And how I can identify the correct one?

推荐答案

我只需要解决这个问题,从我的研究中我知道的问题是身份包含私钥,另一个包含公钥。

I just had to solve this issue and from my reaserch the issue is that one of the identities contains private key and the other one contains public key.

因此,当您尝试检索身份时,您必须添加

So when you're trying to retrieve the identity you have to add

value: kSecAttrKeyClassPrivate / kSecAttrKeyClassPublic
key: kSecAttrKeyClass

到用作 SecItemCopyMatching 过滤器的词典中,例如:

to the dictionary used as filter in SecItemCopyMatching e.g.:

NSMutableDictionary *filterDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             (__bridge id)kSecClassIdentity, kSecClass,
                                             kSecMatchLimitAll,              kSecMatchLimit,
                                             kCFBooleanTrue,                 kSecReturnRef,
                                             kSecAttrKeyClassPrivate,        kSecAttrKeyClass,
                                             nil];

这篇关于SecItemAdd创建两个身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆