Converting .PUB certificate to .PEM

Is there any tool to convert .PUB public key as attached to .PEM or .der or any Open ssl format. and also a command to convert would be much appreciated.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave HoweSoftware and Hardware EngineerCommented:
Not seeing an attachment, but please note the following;

Normally, a pub file is a bare public key, which is half of the RSA public keypair system (one key is used for encryption, one for decryption; the other half is usually a dot-key file containing the secret key, which is the decryption and signature creation key)

a cer file (regardless of format, although pem is customary) contains a "certificate". A certificate (and normally this is to the x509 standard) is a composite containing the public key (so, the pub file contents), some identity data (for both certificate owner and certificate issuer) and a digital signature (created by the issuer using their own secret key) that proves that the identity data has not changed since the cert was issued (there is also some usage timeframe data and so forth but that's commercial; certs pretty much have a validity range so that they can sell you another once that expires)

So, with that in mind, it is usually easy to get from a cer to a pub (just as you can easily take a single pencil from a set of coloured pencils) but near impossible to get from just a pub to the original cer (again, you can't get easily from one pencil to an entire set)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
btanExec ConsultantCommented:
this tool can be handy which also include the openssl conversion in the article.
SSL Converter to convert SSL certificates to and from different formats such as pem, der, p7b, and pfx. Different platforms and devices require SSL certificates to be converted to different formats. For example, a Windows server exports and imports .pfx files while an Apache server uses individual PEM (.crt, .cer) files.

Most will use pem instead of pub hence use of openssl such as below can be considered before starting off to various conversion needs e.g
openssl genrsa -out temp.pem 1024
openssl rsa -in temp.pem -pubout -out
Dave HoweSoftware and Hardware EngineerCommented:
@btan can't think of anything that would take a pub if a cer is required....
Webinar: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. Join us in our upcoming webinar as we discuss how to best defend against these attacks!

btanExec ConsultantCommented:
I see .pub as the public key so that can be extracted from cert into pem or already generated separately. Just seeing it in a simpler context if all we want is the public key to be in various format.

With Base64 encoding content of public key
"-----END X509 CERTIFICATE----".
In RFC represented in ASN as
 SubjectPublicKeyInfo  ::=  SEQUENCE  {
     algorithm            AlgorithmIdentifier,
     subjectPublicKey     BIT STRING  }
Dave HoweSoftware and Hardware EngineerCommented:
that is true, but normally the pub will already be in pem format - but won't be a cert in pem format, just the public key.
For example:
-----END PUBLIC KEY-----

Open in new window

Is the public key for experts-exchange
btanExec ConsultantCommented:
Agree Dave indeed. Better to work off using  pem in those format..into .der or others as shared in
kalyangkmAuthor Commented:

Nice discussion. So looks like we cant extract anything useful from just the .PUB unless we have a RSA public key pair?
Dave HoweSoftware and Hardware EngineerCommented:
More that there isn't anything useful extractable from a PUB file, as it is just the public key, itself extractable from either the keypair or the certificate; the PUB is a single element of a larger collection, and contains just whatever numbers make up a key of that type (for RSA that would be exponent and modulus; for DSA or EC they would be values appropriate to those types, of course).

to give a (further) example, for the public key above ( the openssl rsa tool extracts:
Public-Key: (2048 bit)
Exponent: 65537 (0x10001)

Open in new window

btanExec ConsultantCommented:
yes in a way - The RSA private key format includes all the public elements. When you get the private key you really have both the private and public key. The public key needs to be derived from the private key. Unless you already have it in pem format...which it must be shared from the owner of the key pair ..

Like an example below is to get the pub key from the private key

Generate a 2048 bit RSA Key
- openssl genrsa -des3 -out private.pem 2048

Export the RSA Public Key to a File
- openssl rsa -in private.pem -outform PEM -pubout -out public.pem
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.