Keytool Generate Private Key From Certificate
Keytool Generate Private Key From Certificate 4,9/5 4798 reviews

How can I find the private key for my SSL certificate. If you just got an issued SSL certificate and are having a hard time finding the corresponding private key, this article can help you to find that one and only key for your certificate. To Use keytool to Create a Server Certificate. Run keytool to generate a new key pair in the default development keystore file, keystore.jks. This example uses the alias server-alias to generate a new public/private key pair and wrap the public key into a self-signed certificate inside keystore.jks. The key pair is generated by using an algorithm of type RSA, with a default password of changeit.

In this tutorial, we demonstrate how to extract a private key from the Java KeyStore (JKS) in your projects using OpenSSL and Keytool. Extracting a Private Key From the Java Keystore (JKS) - DZone. Mar 13, 2019  If you have the private key and public key, execute the following command: openssl x509 -x509toreq -in -out -signkey Once you generate the CSR, you need to submit the CSR to your certificate authority to get a new CA-signed certificate.

To Generate a Certificate by Using keytool

By default, the keytool utility creates a keystorefile in the directory where the utility is run.

Before You Begin

To run the keytool utility, your shell environmentmust be configured so that the J2SE /bin directory is inthe path, otherwise the full path to the utility must be present on the commandline.

  1. Change to the directory that contains the keystore and truststorefiles.

    Always generate the certificate in the directory containingthe keystore and truststore files. The default is domain-dir/config.

  2. Generate the certificate in the keystore file, keystore.jks,using the following command format:


    Use any unique name as your keyAlias. Ifyou have changed the keystore or private key password from the default (changeit), substitute the new password for changeit.The default key password alias is s1as.

    A prompt appears that asks for your name, organization, and other information.

  3. Export the generated certificate to the server.cer file(or client.cer if you prefer), using the following commandformat:


  4. If a certificate signed by a certificate authority is required,see To Sign a Certificate by Using keytool.

  5. Create the cacerts.jks truststore file andadd the certificate to the truststore, using the following command format:


    If you have changed the keystore or private key password from the default(changeit), substitute the new password.

    Information about the certificate is displayed and a prompt appearsasking if you want to trust the certificate.

  6. Type yes, then press Enter.

    Generating a 4096 bit rsa private key. Informationsimilar to the following is displayed:


  7. To apply your changes, restart GlassFish Server. See To Restart a Domain.

Example 11–10 Creating a Self-Signed Certificate in a JKS Keystore by Using an RSAKey Algorithm

RSA is public-key encryption technology developed by RSA Data Security,Inc.


Example 11–11 Creating a Self-Signed Certificate in a JKS Keystore by Using a DefaultKey Algorithm


Example 11–12 Displaying Available Certificates From a JKS Keystore


Keytool Export Private Key And Certificate From Keystore

Example 11–13 Displaying Certificate information From a JKS Keystore


Keytool generate keystore
See Also

For more information about keytool, see the keytool reference page.

Steps to generate self-signed PKCS#12 SSL certificate and export its keys:

1- Create PKCS#12 keystore (.p12 or .pfx file)

  • myKeystore.p12 = keystore filename. It can with .pfx extension as well.
  • MY_PASSWORD = password used for the keystore and the private key as well.
  • CN = commonName, it will be shown as certiciate name in certificates list.
  • OU = organizationUnit, department name for example.
  • O = organizationName, the company name.
  • L = localityName, the city.
  • S = stateName, the state.
  • C = country, the 2-letter code of the country.

Note: This step can be done using openssl but it's more complicated.

Keytool Generate Private Key From Certificate Free

2- Create the public certificate (has the header -----BEGIN CERTIFICATE-----):

Using keytool:

Or using openssl:

Note: Import public-certificate.pem into browsers to trust it. Add it to 'Trusted Root Certification Authorities' certificate store.

3- Export the private key (has the header -----BEGIN PRIVATE KEY-----):

Advantages Of Private Key Encryption

4- Export the public key from the private key (has the header -----BEGIN PUBLIC KEY-----):