玛塔 2015-11-11 09:21 采纳率: 50%
浏览 1695
已采纳

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
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)