玛塔 2015-11-10 10:20 采纳率: 50%
浏览 673

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 求大神帮解决 求指点 跪求卡这 卡崩溃了

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划