本文介绍了如何在XCode中加载证书(.pfx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我正在尝试使用Xcode 6.1.1在我的iPhone 5S上构建一个iOS应用程序,它在我的iPhone设备上运行良好。 但我的一个功能(我正在使用chilkat产品)来自(chilkatsoft.com)需要加载证书(.pfx)(存储在我的桌面上),但它无法打开或读取文件。 i收到错误消息没有这样的文件或目录无法打开文件 该功能的工作原理如下:I'm trying to build an iOS app on my iPhone 5S using Xcode 6.1.1, and it's working fine on my iPhone device.But one of my functions (i'm using chilkat products)from (chilkatsoft.com) requires to load a certificate (.pfx) (which is stored on my desktop), but it cannot open or read the file.i get an error message "No such file or directory Failed to open file"the function works as follows:<pre lang="objc"> - (void)loadClientDigitalCertificateFromPFX:(int)flag { CkoCert * cert = [[CkoCert alloc] init]; BOOL成功; //从PFX文件加载 NSString * pfxFilename; pfxFilename = @/ Users / user / Desktop / Rania.pfx; NSString * pfxPassword; pfxPassword = @**********; // PFX通常包含认证链中的证书。 // Chilkat cert对象将选择最远离root权限证书的证书w / //私钥。 //访问所有证书在PFX中,使用 //改为Chilkat证书商店对象。 success = [cert LoadPfxFile:pfxFilename密码:pfxPassword]; if(success!= YES) { NSLog(@%@,cert.LastErrorText); NSLog(@ERROR); //返回; } //获取有关数字证书的一些信息, //然后获取私钥... // DN =杰出名称 / * NSLog(@主题DN:%@,证书。 SubjectDN); NSLog(@Common Name:%@,cert.SubjectCN); NSLog(@发行人通用名称:%@,cert.IssuerCN); NSLog(@序列号:%@,cert.SerialNumber); * / // ************************************** ******************* if(flag == 1) //现在获取私钥将其导出为XML格式 { CkoPrivateKey * pkey; pkey = [cert ExportPrivateKey]; if(pkey == nil){ NSLog(@%@,cert.LastErrorText); //返回; } NSString * prvkeyXml; //获取XML格式的私钥: prvkeyXml = [pkey GetXml]; // NSLog (@客户私钥:%@,prvkeyXml); 返回prvkeyXml; } // ****** ************************************************** else { //获取公钥并将其导出为XML格式 CkoPublicKey * pubkey; pubkey = [cert ExportPublicKey]; if(pubkey) == nil){ NSLog(@%@,cert.LastErrorText); //返回; } NSString * pubkeyXml; pubkeyXml = [pubkey GetXml]; // NSLog(@客户公钥:%@, pubkeyXml); 返回pubkeyXml; } } // ======== ================================================== ===================== 以下是我收到的错误消息:- (void)loadClientDigitalCertificateFromPFX:(int)flag{ CkoCert *cert = [[CkoCert alloc] init]; BOOL success; // Load from the PFX file NSString *pfxFilename; pfxFilename = @"/Users/user/Desktop/Rania.pfx"; NSString *pfxPassword; pfxPassword = @"**********"; // A PFX typically contains certificates in the chain of authentication. // The Chilkat cert object will choose the certificate w/ // private key farthest from the root authority cert. // To access all the certificates in a PFX, use the // Chilkat certificate store object instead. success = [cert LoadPfxFile: pfxFilename password: pfxPassword]; if (success != YES) { NSLog(@"%@",cert.LastErrorText); NSLog(@"ERROR"); // return; } // Get some information about the digital certificate, // then get the private key... // DN = "Distinguished Name" /*NSLog(@"Subject DN: %@",cert.SubjectDN); NSLog(@"Common Name: %@",cert.SubjectCN); NSLog(@"Issuer Common Name: %@",cert.IssuerCN); NSLog(@"Serial Number: %@",cert.SerialNumber);*/ //********************************************************* if(flag == 1) // Now get the private key and Export it into an XML format { CkoPrivateKey *pkey; pkey = [cert ExportPrivateKey]; if (pkey == nil ) { NSLog(@"%@",cert.LastErrorText); //return; } NSString *prvkeyXml; // Get the private key in XML format: prvkeyXml = [pkey GetXml]; //NSLog(@"Client Private Key: %@", prvkeyXml); return prvkeyXml; } //******************************************************** else { // Get the public key and Export it into XML format CkoPublicKey *pubkey; pubkey = [cert ExportPublicKey]; if (pubkey == nil ) { NSLog(@"%@",cert.LastErrorText); //return; } NSString *pubkeyXml; pubkeyXml = [pubkey GetXml]; //NSLog(@"Client Public Key: %@", pubkeyXml); return pubkeyXml; }}//===============================================================================the following is the error message i get:2015-02-16 21:46:55.749 newDGCH2[1875:812662] ChilkatLog: LoadPfxFile: DllDate: Jan 22 2015 ChilkatVersion: 9.5.0.47 UnlockPrefix: ******** Architecture: Little Endian; 64-bit Language: IOS Objective-C VerboseLogging: 0 class: Cert pfxPath: /Users/user/Desktop/Rania.pfx loadFileX: pathQP: /Users/user/Desktop/Rania.pfx fopen_failed: errno: 2 osErrorMessage: No such file or directory Failed to open file. mode: r path: /Users/user/Desktop/Rania.pfx --fopen_failed Failed to open for read. --loadFileX Failed. --LoadPfxFile--ChilkatLog2015-02-16 21:46:55.751 newDGCH2[1875:812662] ChilkatLog: LoadPfxFile: DllDate: Jan 22 2015 ChilkatVersion: 9.5.0.47 UnlockPrefix: ******** Architecture: Little Endian; 64-bit Language: IOS Objective-C VerboseLogging: 0 class: Cert pfxPath: /Users/user/Desktop/Rania.pfx loadFileX: pathQP: /Users/user/Desktop/Rania.pfx fopen_failed: errno: 2 osErrorMessage: No such file or directory Failed to open file. mode: r path: /Users/user/Desktop/Rania.pfx --fopen_failed Failed to open for read. --loadFileX Failed. --LoadPfxFile--ChilkatLog b $ b 所以,我想知道是什么问题,XCode可以从桌面打开证书吗?或者 我必须从Keychain Access导入它还是什么? i毫无头绪!!!!! 有人可以帮帮我:) 最好的问候。 RaniaSo, i was wondering what is the problem, can XCode open a certificate from the desktop? ORdo i have to import it from the Keychain Access or what?i have no clue!!!!!Can somebody please help me :)Best Regards.Rania推荐答案它说没有这样的文件。尝试使用〜/ Desktop / Rania.pfx作为路径。如果您正在尝试访问其他用户的桌面,这不是一个好习惯,因此系统安全性是禁止的。 此外,如果代码在您的iPhone,它试图访问iPhone的桌面。你的证书在Mac的桌面上,不是吗?It says there is no such file. Try "~/Desktop/Rania.pfx" as the path. If you're trying to access other user's desktop, that is not a good practice and therefore is forbidden by system security.Also, if the code is running on your iPhone, it tries to access iPhone's desktop. Your certificate is on the Mac's desktop, isn't it? 这篇关于如何在XCode中加载证书(.pfx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 14:36