How to generate a certificate/PEM from specific plain text keys? Is there a way to generate a certificate with a pre-stablished public/private plaint text keys?

Explaning: I generated some keys on a web site for development propurses, but now one of the parties requires it on a X509 certificate...

Sample keys can be generated here: http://travistidwell.com/jsencrypt/demo/
Yes, of course this is possible.

Generally you are required to first create a certificate (signing) request or CSR - a specific structure sometimes also called PKCS#10 after the standard that defines it. The certificate request contains the public key inside of it. This certificate request needs to be signed with the pre-established private key for the certificate. This certificate request can processed by a local or remote certificate authority, which returns the certificate. Commonly the certificate or certificate chain and the private key then need to be stored together into a (PKCS#12) key store.

Alternatively you should also be able to directly to create a self-signed certificate. Again, the public key is contained in the certificate. And again, the private key is required to perform the signing.

Note that the public key is commonly also contained in the (PKCS#1 or PKCS#8) structure of the private key. This means that you may not have to explicitly include it in any commands for creating the certificate request or self-signed certificate.



I found some answers on this page on how to do this with OpenSSL:

Generate a CSR from an Existing Private Key

openssl req \
       -key domain.key \
       -new -out domain.csr


Generate a Self-Signed Certificate from an Existing Private Key

openssl req \
       -key domain.key \
       -new \
       -x509 -days 365 -out domain.crt


here the domain.key is the OpenSSL PEM encoded private key.



I've tested both methods successfully after copying the private key to a file called domain.key. If this goes wrong, it's likely because of copying or system issues.