玛塔
2015-11-11 09:21
采纳率: 50%
浏览 1.7k

iOS NSData转SecKeyRef私钥对象的时候为null

-(SecKeyRef)getPrivateKeyRef{

Byte byte[]={0xf3,0xfc,0xcc,0x0d,0x00,0xd8,0x03,0x19,0x54,0xf9,0x08,0x64,0xd4,0x3c,0x24,0x7f,0x4b,0xf5,0xf0,0x66,0x5c,0x6b,0x50,0xcc,0x17,0x74,0x9a,0x27,0xd1,0xcf,0x76,0x64};

NSData *p12Data =[NSData dataWithBytes:byte length:32];
 NSLog(@"%@",p12Data);
NSMutableDictionary * options = [[NSMutableDictionary alloc] init];
SecKeyRef privateKeyRef = NULL;
//change to the actual password you used here
[options setObject:@"password_for_the_key" forKey:(id)kSecImportExportPassphrase];
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
OSStatus securityError = SecPKCS12Import((CFDataRef) p12Data,
                                         (CFDictionaryRef)options, &items);

if (securityError == noErr && CFArrayGetCount(items) > 0) {
    CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0);
    SecIdentityRef identityApp =
    (SecIdentityRef)CFDictionaryGetValue(identityDict,
                                         kSecImportItemIdentity);
    securityError = SecIdentityCopyPrivateKey(identityApp, &privateKeyRef);
    if (securityError != noErr) {
        privateKeyRef = NULL;
    }
}
CFRelease(items);
NSLog(@"%@",privateKeyRef);
return privateKeyRef;

}
不走if语句输出的privateKeyRef为null 求大神帮解决 求指点 跪求卡这 卡崩溃了
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 玛塔 2015-11-12 10:50
    已采纳

    行政村周星驰似懂非懂神烦大叔

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题