title: Extract public key from private key in pem format
body: <p>How can I implement the effect of following command in Objective-C?</p>
  
  <pre><code>openssl rsa -in mykey.pem -pubout &gt; mykey.pub
  </code></pre>
  
  <p>I'm able to generate a private key in pem format.</p>
  
  <p>Here is the code I use to read the private key into a openssl RSA object.</p>
  
  <pre class="lang-objc prettyprint-override"><code>BIO* bpPrivate = nil;
  NSString *filePath = .....
  const char *path = [filePath UTF8String];
  bpPrivate = BIO_new_file(path, "r");
  _rsa = PEM_read_bio_RSAPrivateKey(bpPrivate, NULL, 0, NULL);
  </code></pre>
  
  <p>I want to extract the public key from the private key.</p>