Keytool Generate Public Key From Private Key

A lost SSH public-key or a web service generates an SSH key but does not provide the public-key part to you. What to do now? There is a solution for this situation.

  1. Generate Rsa Public Private Key
  2. Keytool Generate Public Key From Private Key Ssh
  3. Generate Public Private Key Pair
  4. Generate Private And Public Key

Apr 23, 2012 To create a private/public key with the alias specified by the user, enter: keytool -genkey -keyalg RSA -alias -keystore keystore.jks -storepass -keypass is the user-chosen alias for the private and public keys that will function as a user name for logging in using RSA. Generate public and private keys # Generate a private key openssl genrsa -out./private.pem 2048 # Generate a public key from a private key openssl rsa -pubout-in private.pem -out./public.pem # Get the fingerprint from the private key openssl rsa -pubout-outform DER -in private.pem openssl md5 -c Create client JKS from pem files. Jan 17, 2019  Exporting the public key from a JSK is quite straightforward with the keytool utility, but exporting the private key is not allowed. Therefore, we need to get the support of the openssl utility for that. Additionally, you can write some custom Java code to get the private key extracted as well. The private key is generated simultaneously with the CSR (certificate signing request), containing the domain name, public key and additional contact information. The CSR is to be sent to the certificate authority for validation and signing immediately after the certificate activation in. If you could re-generate the private key only from the CSR or the certificate, anyone could impersonate the entity to which the certificate has been issued. If you've lost your private key, you'll simply have to create a new key-pair, submit a new CSR and get a new certificate.

When you have an SSH key you need the public key to setup SSH passwordless login with SSH-key. But if you have lost the public key part but still have the private key, there is a way to regenerate the key.

With the public key missing, the following command will show you that there is no public key for this SSH key.

The -l option instructs to show the fingerprint in the public key while the -f option specifies the file of the key to list the fingerprint for.

To generate the missing public key again from the private key, the following command will generate the public key of the private key provided with the -f option.

Keytool generate public key from private keyboard

The -y option will read a private SSH key file and prints an SSH public key to stdout. The public key part is redirected to the file with the same name as the private key but with the .pub file extension. If the key has a password set, the password will be required to generate the public key.

To check the details of the generated public key execute the following command as shown above.

The output of this command shows the key size as the first column, the fingerprint as the second column and after the file name, the type is shown in brackets. In the example above, a 4096 bit RSA key.

Add private key to keystore

Read more of my posts on my blog at http://blog.tinned-software.net/.

Related posts:

Generate Rsa Public Private Key

If a code signer does not yet have a suitable private key for signing the code, the key must first be generated, along with a corresponding public key that can be used by the code receiver's runtime system to verify the signature.

Since this lesson assumes that you don't yet have such keys, you are going to create a keystore named examplestore and create an entry with a newly generated public/private key pair (with the public key in a certificate).

Type the following command in your command window to create a keystore named examplestore and to generate keys:

You will be prompted to enter passwords for the key and keystore.

Subparts of the keytool Command

Let's look at what each of the keytool subparts mean.

Keytool Generate Public Key From Private Key Ssh

  • The command for generating keys is -genkey.
  • The -alias signFiles subpart indicates the alias to be used in the future to refer to the keystore entry containing the keys that will be generated.
  • The -keystore examplestore subpart indicates the name (and optionally path) of the keystore you are creating or already using.
  • The storepass value that you are promted for specifies the keystore password.
  • The keypass value that you are prompted for specifies a password for the private key about to be generated. You will always need this password in order to access the keystore entry containing that key. The entry doesn't have to have its own password. When you are prompted for the key password, you are given the option of letting it be the same as the keystore password.

Generate Public Private Key Pair

Note: For security reasons you should not set your key or keystore passwords on the command line, because they can be intercepted more easily that way.

Distinguished-Name Information

If you use the preceding keystore command, you will be prompted for your distinguished-name information. Following are the prompts; the bold indicates what you should type.

Generate Private And Public Key

Command Results

The keytool command creates the keystore named examplestore (if it doesn't already exist) in the same directory in which the command is executed. The command generates a public/private key pair for the entity whose distinguished name has a common name of Susan Jones and the organizational unit of Purchasing.

The command creates a self-signed certificate that includes the public key and the distinguished-name information. (The distinguished name you supply will be used as the 'subject' field in the certificate.) This certificate will be valid for 90 days, the default validity period if you don't specify a -validity option. The certificate is associated with the private key in a keystore entry referred to by the alias signFiles.

Self-signed certificates are useful for developing and testing an application. However, users are warned that the application is signed with an untrusted certificate and asked if they want to run the application. To provide users with more confidence to run your application, use a certificate issued by a recognized certificate authority.

Note: The command could be shorter if option defaults are accepted or you wish to be prompted for various values. Whenever you execute a keytool command, defaults are used for unspecified options that have default values, and you are prompted for any required values. For the genkey command, options with default values include alias (whose default is mykey), validity (90 days), and keystore (the file named .keystore in your home directory). Required values include dname, storepass, and keypass.