Search code examples
cmacoscryptographysecurity.framework

Obtain public key from private SecKeyRef


Given a SecKeyRef loaded using SecItemImport from an RSA private key is there a way to obtain or create a SecKeyRef for only the public key components? In OpenSSL this could be done by copying the modulus and public exponent to a new struct, but SecKeyRef is opaque and I've been unable to find a function that performs this operation.


Solution

  • As of macOS 10.12, iOS/tvOS 10, and watchOS 3 the function SecKeyCopyPublicKey now exists to do this.