程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-iOS NSData轉SecKeyRef私鑰對象的時候為null

ios-iOS NSData轉SecKeyRef私鑰對象的時候為null

編輯:編程綜合問答
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. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved