What is Keytool?

 keytool is a key and certificate management utility. It allows users to administer their own public/private key pairs and associated certificates for use in self-authentication (where the user authenticates himself/herself to other users/services) or data integrity and authentication services, using digital signatures

Java includes the keytool utility in its releases. We use it to manage keys and certificates and store them in a keystore. The keytool command allows us to create self-signed certificates and show information about the keystore.

In the following sections, we're going to go through different functionalities of this utility.

First of all, let's create a self-signed certificate that could be used to establish secure communication between projects in our development environment, for example.

In order to generate the certificate, we're going to open a command-line prompt and use keytool command with the -genkeypair option

keytool -genkeypair -alias <alias> -keypass <keypass> -validity <validity> -storepass <storepass>

Let's learn more about each of these parameters:

  • alias – the name for our certificate
  • keypass – the password of the certificate. We'll need this password to have access to the private key of our certificate
  • validity – the time (in days) of the validity of our certificate
  • storepass – the password for the keystore. This will be the password of the keystore if the store doesn't exist

For example, let's generate a certificate named “cert1” that has a private key of “pass123” and is valid for one year. We'll also specify “stpass123” as the keystore password:

keytool -genkeypair -alias cert1 -keypass pass123 -validity 365 -storepass stpass123

After executing the command, it'll ask for some information that we'll need to provide:

What is your first and last name?
  [Unknown]:  Name
What is the name of your organizational unit?
  [Unknown]:  Unit
What is the name of your organization?
  [Unknown]:  Company
What is the name of your City or Locality?
  [Unknown]:  City
What is the name of your State or Province?
  [Unknown]:  State
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=Name, OU=Unit, O=Company, L=City, ST=State, C=US correct?
  [no]:  yes

As mentioned, if we haven't created the keystore before, creating this certificate will create it automatically.

We could also execute the -genkeypair option without parameters. If we don't provide them in the command line and they're mandatory, we'll be prompted for them


Comments

Popular posts from this blog

Email Sending through O365 using OAuth Protocol

IoT Technology

What is reverse proxy?