如何从Objective C中的文件创建私钥? [英] How to create private key from file in Objective C?

查看:64
本文介绍了如何从Objective C中的文件创建私钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个这样的公钥:

I have created a public key like this:

 NSString *pkFilePath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"];
NSData *myCertData = [NSData dataWithContentsOfFile:pkFilePath];


SecCertificateRef cert = SecCertificateCreateWithData (kCFAllocatorDefault, (CFDataRef)myCertData);
CFArrayRef certs = CFArrayCreate(kCFAllocatorDefault, (const void **) &cert, 1, NULL);

SecTrustRef trust;
SecPolicyRef myPolicy   = SecPolicyCreateBasicX509();
SecTrustCreateWithCertificates(certs, myPolicy, &trust);
SecTrustResultType trustResult;
SecTrustEvaluate(trust, &trustResult);
SecKeyRef pub_key_leaf = SecTrustCopyPublicKey(trust);
NSLog(@"%@",pub_key_leaf);

但是如何从文件创建私钥?

But how to create private key from file?

这是一些创建私钥的相关代码,但我不知道如何使用我的私钥文件从中创建私钥.

Here is some related code to create a private key but I am not getting how to create private key from this using my privatekey file.

https://developer.apple.com/library/mac/#documentation/security/conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html#//apple_ref/doc/uid/TP40001358-CH208-SW10

推荐答案

我遇到了同样的问题,原来你需要使用 p12 文件来导入私钥.

I had the same problem, it turns out you need to use a p12 file to import the private key.

在此处查看我的答案https://stackoverflow.com/a/17295321/480467

这篇关于如何从Objective C中的文件创建私钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆