I lost my public key. Can I recover it from the private key?

I created a key pair + a signed certificate for iOS / OSX development. Somewhere along the way, I lost the public key that comes with my private key. Maybe because Keychain Access does not group private and public keys together, as it does with certificates and private keys (this is so annoying! Why it does (not)!)

In Keychain Access, I can still right-click the private key → Certificate Request; but without a public key, I get the error "The specified item was not found in the keychain." I'm pretty sure public keys can be recovered, but how? Obviously, Keychain Access is not smart enough to do this automatically.

In the end, I realized this and will look for my answer correctly in a few days if someone does not add something new to the answer.

+18
ios iphone openssl keychain macos
May 30 '13 at 22:46
source share
1 answer

I vaguely remember how this could be done using opensl on .pem files, so that the direction I headed.

  • In Keychain Access, export the private key, for example, private.p12 . Apply password or not.
  • Convert it to .pem: openssl pkcs12 -in private.p12 -out private.pem . Enter the password from the previous step. You are forced to apply a password to .pem.
  • Extract the public part: openssl rsa -in private.pem -pubout > public.pem . Enter the password from the previous step.
  • Import to access the keychain: security import public.pem -k login.keychain . If you do not specify a keychain, the import will complete, but I could not find where the item was placed.
  • In Keychain Access, login to the "Imported Public Key" login. Rename it and go to the desired location.
  • Clean yourself, especially those .p12 and .pem private keys with no or bad passwords.
+51
May 30 '13 at 22:46
source share



All Articles