views:

85

answers:

1

I have a certificate .p12 and .crt and I would like store the public key to print it and use the key with an iPhone application. I have seen the iPhone's documentation, but I can't do it...

+1  A: 

This is surprisingly easy. You don't need to add the certificate to the keychain to handle this case. Rather, just load the certificate data (that is, the contents of a .cer file) in your application (you can either get this from your bundle or off the network) and then create a certificate ref using SecCertificateCreateWithData. From there you can extract a public key ref using a SecTrust object (SecTrustCreateWithCertificates, SecTrustEvaluate -- you can choose to ignore the resulting SecTrustResultType -- and SecTrustCopyPublicKey). And from there you can encrypt and verify using the SecKey APIs (SecKeyEncrypt, SecKeyRawVerify).

https://devforums.apple.com/message/114555#114555

Aston