Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have generated RSA private key using below command:

openssl genrsa -out privkey.pem 2048

And created a self signed certificate using below command:

openssl req -new -x509 -key privkey.pem -out cacert.pem -days 3650

Now I am trying to convert cacert .pem file to certificate .cer

Any ideas?

share|improve this question
1  
According to support.ssl.com/Knowledgebase/Article/View/19/0/… .pem is an encoding and .cer is an extension. Shortly: a .cer file may contain both a PEM or a DER encoding. What exactly do you need? (The link should help you.) –  Fabian May 21 at 14:14
    
I found command to create self signed certificate from this link: openssl.org/docs/HOWTO/certificates.txt Here is the complete text: If you don't want to deal with another certificate authority, or just want to create a test certificate for yourself. This is similar to creating a certificate request, but creates a certificate instead of a certificate request. –  Miraaj May 21 at 14:26
    
This does not really answer what you need: What is the purpose of the certificate you generate? Maybe an HTTPS server? Or personal authentication for some application? But I think you already got enough good answers below for what you asked. –  Fabian May 21 at 14:28
    
Scenario is: we are creating public-private key pair at android app and we need to share public key to an iOS app, the only way which I have found to share it is through self signed certificate. iOS apis extract public key from certificate with this extension (an example): some_certificate.cer . For now I am trying to generate some_certificate.cer through terminal and validate if it is able to extract public key from it, and perform encryption using the same. –  Miraaj May 21 at 14:39
    
I cant' help you with iOS stuff. But my understanding is that the .cer extension is only used by Microsoft. If the answers below do not help you, you might want to ask in an iOS programming related place. –  Fabian May 21 at 14:48

3 Answers 3

up vote 3 down vote accepted

You can use the following command:

openssl x509 -inform PEM -in cacert.pem -outform DER -out certificate.cer
share|improve this answer

.cer is a filetype for either DER or Base64 encoding, if I recall correctly.

openssl x509 -in cacert.pem -out cacert.cer -inform pem -outform der for DER format.

share|improve this answer

The actual extension does not matter for certificates. Usually .pem files have an x509 certificate in base64 encoded form. .cer files may be base64 or DER encoded (Windows will recognise either). Depending on your application you will need to find out which certificate format the application requires.

To convert between base64 (PEM) and DER encoding:

openssl x509 -in cert.pem -outform pem -outform der -out cert.cer
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.