Openssl Generate Private Key From Cer

Openssl Generate Private Key From Cer 9,4/10 9578 votes
Ranch Hand
posted 13 years ago
Using java 'keytool' command we generate a private key and public key and also we can export the public key to a .cer file. Now my question is can a .cer file contain a private key. My impression is .cer is a public key certificate that can contain only public key but not private key.
Someone told me that they procured a certificate from VeriSign and they have received a .cer file from VeriSign that contains both private key and public key. Can this be true that .cer file can contain a private key? Please clarify?

Generating a private key and self-signed certificate can be accomplished in a few simple steps using OpenSSL. We provide here detailed instructions on how to create a private key and self-signed certificate valid for 365 days. How to generate private key and CSR from command line. This article describes how to generate a private key and CSR (Certificate Signing Request) from the command line. You may need to do this if you want to obtain an SSL certificate for a system that does not include cPanel access, such as a dedicated server or unmanaged VPS. Reasons for importing keys include wanting to make a backup of a private key (generated keys are non-exportable, for security reasons), or if the private key is provided by an external source. This document will guide you through using the OpenSSL command line tool to generate a key pair which you can then import into a YubiKey. Extracting certificate and private key information from a Personal Information Exchange (.pfx) file with OpenSSL: Open Windows File Explorer. Copy your.pfx file to a computer that has OpenSSL installed, notating the file path. Certificate.pfx files are usually password protected. Obtain the password for your.pfx file.

Greenhorn

Using openssl, I've created a private key as follows: openssl genrsa -out myKey.pem Then, to generate the csr demanded by the CA, I've executed the following: openssl req -new -key myKey.pem -out cert.csr The CA responded with a certificate which I stored in a file named myCert.cer. The following instructions will guide you through the CSR generation process on Nginx (OpenSSL). To learn more about CSRs and the importance of your private key, reference our Overview of Certificate Signing Request article. If you already generated the CSR and received your trusted SSL certificate, reference our SSL Installation Instructions and disregard the steps below. The commands below demonstrate examples of how to create a.pfx/.p12 file in the command line using OpenSSL: PEM (.pem,.crt,.cer) to PFX openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile more.crt.

posted 13 years ago
I'm sure there would be a way to put a private key into the '.cer' file, but I'm equally certain this would be silly. The point of the certificate is to distribute the public key. If you distribute the private key, the public key is worthless. Likewise, I am pretty certain that your friend did _not_ get a '.cer' from VeriSign with a private key in it.
The general approach to getting certificates is to create the public/private key pair (these are _not_ the same value, each one is unique - but related). Then using the 'public' key (it doesn't matter which one of the two you declare as 'public', but one will be put into the certificate, and the other will be protected from anyone getting access - hence one is 'public' and the other is 'private'), you will generate a 'Certificate Signing Request' (CSR - following 'PKCS#10' specification from RSA). The CSR will contain identifying information about the certificate requestor, and the public key. This is sent to the Certification Authority (CA - e.g. VeriSign), who will (hopefully) verify the identity of the requestor, and issue the certificate (the '.CER' file). The issued certificate will contain all of the identifying information supplied to the CA, the public key from the requestor, _AND_ the CA's digital signature (a digest/hash of the data in the certificate, encrypted with the CA's private key). In order to verify the certificate, you simply use the CA's public key (which you get from their certificate), and decrypt the digest/hash value, and then run your own hash/digest of the certificate you were given - if the one in the signature matches the digest you generated - the certificate is the one issued by the CA.
If your private key is given out, then both the public and private keys are essentially useless. Sure, they can encrypt/decrypt for each other - but _anyone_ could perform either side of the equation, which means that you could never be sure who was doing what.

This is a simple doc on generating certificates with OpenSSL.It focus on three different certificate types, exactly the classic RSA and ECDSA and the relative new RSASSA-PSS.It generates a CA and an end entity (EE) certificate for each type.The content is straightforward and concise: Commands with comments.

Please note that the commands on different certificate types are quite similar.Especially, the private key generation on different algorithms just uses tool genpkey, though some algorithms (e.g. RSA) have their own tool (e.g. genrsa).This is deliberate. In further development, these commands could be abstracted as a single common certificate generation facility.

Openssl Generate Private Key From Cer File

OpenSSL configurations

RSA certificates

EC certificates

Openssl Generate Private Key From Certificate

These commands and options are quit similar to those in section RSA certificates.The main difference is the private key generation.

RSASSA-PSS certificates

Generate Key With Openssl

These commands and options are almost the same as those in section RSA certificates.The only difference is the public key algorithm, of course rsa-pss here.

Openssl Create Private Key From Cer

DSA certificates

Openssl Generate Public Key From Certificate

These commands and options are quite similar to those in section RSA certificates.The main difference is that it needs to generate key parameters before generating key.