Generating a KeyStore and TrustStore

The following sections explain how to create both a KeyStoreand a TrustStore (or import a certificate into an existing TrustStoresuch as the default Logical Host TrustStore in the location:


Key
  1. These commands allow you to generate a new Java Keytool keystore file, create a CSR, and import certificates. Any root or intermediate certificates will need to be imported before importing the primary certificate for your domain. Generate a Java keystore and key pair keytool -genkey -alias mydomain-keyalg RSA -keystore keystore.jks -keysize 2048.
  2. For more information about the keystore, see Finding your Keystore's MD5 or SHA1 Signature. After clicking Ad-Hoc, Visual Studio for Mac opens the Android Signing Identity dialog as shown in the next screenshot. To publish the.APK, it must first be signed it with a signing key (also referred to as a certificate).
  3. May 07, 2019  In this article, we talked about managing certificates and keys using KeyStore API. We discussed what a keystore is, how to create, load and delete one, how to store a key or certificate in the keystore and how to load and update existing entries with new values. The full implementation of the example can be found over on Github.
  4. To support secure importing of encrypted keys into the Keystore, complete the following steps: Generate a key pair that uses the PURPOSEWRAPKEY purpose. It's recommended that you add attestation to this key pair, as well. On a server or machine that you trust, generate the ASN.1 message that the SecureKeyWrapper should contain.
  5. KeyStore Explorer is an open source GUI replacement for the Java command-line utilities keytool and jarsigner. KeyStore Explorer presents their functionality,.

where <c:JavaCAPS> isthe directory where Java CAPS is installed and <MyDomain> isthe name of your domain. The primary tool used is keytool, but openssl isalso used as a reference for generating pkcs12 KeyStores.

Creating a KeyStore in JKS Format. This section explains how to create a KeyStore using the JKS format as the database format for both the private key, and the associated certificate or certificate chain. By default, as specified in the java.security file, keytool uses JKS as the format of the key and certificate databases (KeyStore. Create a new keystore: Open a command prompt in the same directory as Java keytool; alternatively, you may specify the full path of keytool in your command. Pay close attention to the alias you specify in this command as it will be needed later on.

For more information on openssl andavailable downloads, visit the following web site:

http://www.openssl.org.

Creating a KeyStore in JKS Format

This section explains how to create a KeyStore using theJKS format as the database format for both the private key, and theassociated certificate or certificate chain. By default, as specifiedin the java.security file, keytool usesJKS as the format of the key and certificate databases (KeyStore andTrustStores). A CA must sign the certificate signing request (CSR).The CA is therefore trusted by the server-side application to whichthe Adapter is connected.

Note –

Itis recommended to use the default KeyStore


where <c:JavaCAPS> isthe directory where Java CAPS is installed and <MyDomain> isthe name of your domain.

To Generate a KeyStore

  1. Perform the following command.


  2. Once prompted, enter the information required to generatea CSR. A sample key generation section follows.


    If the KeyStore password is specified, then the password mustbe provided for the adapter.

  3. Press RETURN when prompted for the key password (thisaction makes the key password the same as the KeyStore password).

    This operation creates a KeyStore file clientkeystore in the current working directory. You must specify a fullyqualified domain for the “first and last name” question.The reason for this use is that some CAs such as VeriSign expect thisproperties to be a fully qualified domain name.

    Thereare CAs that do not require the fully qualified domain, but it isrecommended to use the fully qualified domain name for the sake ofportability. All the other information given must be valid. If theinformation cannot be validated, a CA such as VeriSign does not signa generated CSR for this entry.

    Microsoft Streets & Trips makes trip planning easy.Product FeaturesIncludes updated street level maps for U.S. Microsoft streets and trips 2010 product key generator.

    This KeyStore containsan entry with an alias of client.This entry consists of the generated private key and information neededfor generating a CSR as follows:


    This command generates a certificate signing request which canbe provided to a CA for a certificate request. The file client.csr contains the CSR in PEM format.

    Some CA (one trusted by the web server to which the adapteris connecting) must sign the CSR. The CA generates a certificate forthe corresponding CSR and signs the certificate with its private key.For more information, visit the following web sites:

    or

    If the certificate is chained with the CA’scertificate, perform step 4; otherwise, perform step 5 in the followinglist:

  4. Perform the following command.


    The command imports the certificate and assumes the client certificateis in the file client.cer and theCA’s certificate is in the file CARoot.cer.

  5. Perform the following command to import the CA’scertificate into the KeyStore for chaining with the client’scertificate.


  6. Perform the following command to import the client’scertificate signed by the CA whose certificate was imported in thepreceding step.


    The generated file clientkeystore containsthe client’s private key and the associated certificate chainused for client authentication and signing. The KeyStore and/or clientkeystore, can then be used as the adapter’sKeyStore.

Creating a KeyStore in PKCS12 Format

This section explains how to create a PKCS12 KeyStoreto work with JSSE. In a real working environment, a customer couldalready have an existing private key and certificate (signed by aknown CA). In this case, JKS format cannot be used, because it doesnot allow the user to import/export the private key through keytool. It is necessary to generate a PKCS12database consisting of the private key and its certificate.

The generated PKCS12 database can then be used as the Adapter’sKeyStore. The keytool utility iscurrently lacking the ability to write to a PKCS12 database. However,it can read from a PKCS12 database.

Note –

There are additional third-party tools available for generatingPKCS12 certificates, if you want to use a different tool.

For the following example, openssl isused to generate the PKCS12 KeyStore:


The existing key is in the file mykey.pem.txt in PEM format. The certificate is in mycertificate.pem.txt, which is also in PEM format. A textfile must be created which contains the key followed by the certificateas follows:


Generate Key Keystore

This command prompts the user for a password. The password isrequired. The KeyStore fails to work with JSSE without a password.This password must also be supplied as the password for the Adapter’sKeyStore password.

This command also uses the openssl pkcs12 commandto generate a PKCS12 KeyStore with the private key and certificate.The generated KeyStore is mykeystore.pkcs12 withan entry specified by the myAlias alias.This entry contains the private key and the certificate provided bythe -in argument. The noiter and nomaciter optionsmust be specified to allow the generated KeyStore to be recognizedproperly by JSSE.

Creating a TrustStore

For demonstration purposes, suppose you have the followingCAs that you trust: firstCA.cert, secondCA.cert,thirdCA.cert, located in the directory C:cascerts. You can create a new TrustStore consistingof these three trusted certificates.

To Create a New TrustStore

  1. Perform the following command.


  2. Enter this command two more times, but for the secondand third entries, substitute secondCA and thirdCA for firstCA.Each of these command entries has the following purposes:

    • The first entry creates a KeyStore file named myTrustStore in the current working directoryand imports the firstCA certificateinto the TrustStore with an alias of firstCA.The format of myTrustStore is JKS.

    • For the second entry, substitute secondCA to import the secondCA certificateinto the TrustStore, myTrustStore.

    • For the third entry, substitute thirdCA to import the thirdCA certificateinto the TrustStore.

    Once completed, myTrustStore is available to be used as theTrustStore for the adapter.

Java Keytool is a key and certificate management utility. It allows users to manage their own public/private key pairs and certificates. It also allows users to cache certificates. Java Keytool stores the keys and certificates in what is called a keystore. By default the Java keystore is implemented as a file. It protects private keys with a password. A Keytool keystore contains the private key and any certificates necessary to complete a chain of trust and establish the trustworthiness of the primary certificate.

Each certificate in a Java keystore is associated with a unique alias. When creating a Java keystore you will first create the .jks file that will initially only contain the private key. You will then generate a CSR and have a certificate generated from it. Then you will import the certificate to the keystore including any root certificates. Java Keytool also several other functions that allow you to view the details of a certificate or list the certificates contained in a keystore or export a certificate.

Note: For easier management of your Java Keystores (using a GUI) check out Portecle. If you need to buy a certificate, try to compare SSL with our SSL Wizard.

Below, we have listed the most common Java Keytool keystore commands and their usage:

Java Keytool Commands for Creating and Importing

These commands allow you to generate a new Java Keytool keystore file, create a CSR, and import certificates. Any root or intermediate certificates will need to be imported before importing the primary certificate for your domain.

  • Generate a Java keystore and key pair
  • Generate a certificate signing request (CSR) for an existing Java keystore
  • Import a root or intermediate CA certificate to an existing Java keystore
  • Import a signed primary certificate to an existing Java keystore
  • Generate a keystore and self-signed certificate (see How to Create a Self Signed Certificate using Java Keytoolfor more info)

Java Keytool Commands for Checking

If you need to check the information within a certificate, or Java keystore, use these commands.

  • Check a stand-alone certificate
  • Check which certificates are in a Java keystore
  • Check a particular keystore entry using an alias

Other Java Keytool Commands

  • Delete a certificate from a Java Keytool keystore
  • Change a Java keystore password
  • Export a certificate from a keystore
  • List Trusted CA Certs
  • Import New CA into Trusted Certs
Android

If you need to move a certificate from Java Keytool to Apache or another type of system, check out these instructions for converting a Java Keytool keystore using OpenSSL. For more information, check out the Java Keytool documentation or check out our Tomcat SSL Installation Instructions which use Java Keytool.

Generate A Key And Keystore Password

Originally posted on Sun Jul 13, 2008