Skip to main content

How to Generate a Keystore and CSR Using the Keytool Command

How to Generate a Keystore and CSR Using the Keytool Command


Understanding of the Flow

  1. Generate a keystore and key pair using keytool -genkeypair.
  2. Generate a CSR from the keystore using keytool -certreq.
  3. Submit the CSR to a Certificate Authority (CA) to get a signed certificate.
  4. Import the CA's root certificate into the keystore using keytool -import.
  5. Import the signed certificate into the keystore using keytool -import.


Steps:

Step 1: Generate a Keystore

  1. Open a Terminal or Command Prompt:

    • Ensure you have Java installed, as the keytool command is part of the Java Development Kit (JDK).
  2. Generate the Keystore:

    • Run the following command to create a new keystore and generate a key pair (public/private key) within it.

    keytool -genkeypair -alias mykey -keyalg RSA -keysize 2048 -keystore mykeystore.jks -validity 365

    Explanation:

    • -genkeypair: Generates a key pair (public and private key).
    • -alias mykey: An alias for the key pair. This is used to identify the key pair within the keystore.
    • -keyalg RSA: The algorithm to use for the key pair (RSA in this case).
    • -keysize 2048: The size of the key (2048 bits).
    • -keystore mykeystore.jks: The name of the keystore file to create.
    • -validity 365: The validity period of the generated certificate (365 days).
  3. Enter Keystore Password:

    • You will be prompted to enter a password for the keystore. This password is used to protect the keystore file.
  4. Provide Distinguished Name Information:

    • You will be prompted to enter details for the Distinguished Name (DN) of the certificate:
      • What is your first and last name? (Common Name, CN)
      • What is the name of your organizational unit? (Organizational Unit, OU)
      • What is the name of your organization? (Organization, O)
      • What is the name of your City or Locality? (Locality, L)
      • What is the name of your State or Province? (State, ST)
      • What is the two-letter country code for this unit? (Country, C)
  5. Confirm Information:

    • You will be asked to confirm the information you entered. If everything is correct, type yes and press Enter.
  6. Enter Key Password:

    • You will be prompted to enter a password for the key pair. You can press Enter to use the same password as the keystore password.

Step 2: Generate a Certificate Signing Request (CSR)

  1. Generate the CSR:

    • Run the following command to generate a CSR from the keystore.

    keytool -certreq -alias mykey -keystore mykeystore.jks -file mycsr.csr

    Explanation:

    • -certreq: Generates a certificate signing request.
    • -alias mykey: The alias of the key pair for which the CSR is generated.
    • -keystore mykeystore.jks: The keystore that contains the key pair.
    • -file mycsr.csr: The name of the file to which the CSR will be written.
  2. Enter Keystore Password:

    • You will be prompted to enter the keystore password to access the keystore.

Step 3: Submit the CSR to a Certificate Authority (CA)

  1. Submit the CSR:
    • The mycsr.csr file contains the CSR. Submit this file to a Certificate Authority (CA) to request a signed certificate. The CA will verify your information and provide you with a signed certificate.

Step 4: Import the Signed Certificate

  1. Import the CA's Root Certificate:

    • Before importing the signed certificate, you need to import the CA's root certificate into your keystore.

    keytool -import -alias caroot -file caroot.crt -keystore mykeystore.jks

    Explanation:

    • -import: Imports a certificate into the keystore.
    • -alias caroot: An alias for the CA root certificate.
    • -file caroot.crt: The file that contains the CA root certificate.
    • -keystore mykeystore.jks: The keystore into which the certificate will be imported.
  2. Import the Signed Certificate:

    • After receiving the signed certificate from the CA, import it into your keystore.

    keytool -import -alias mykey -file mycert.crt -keystore mykeystore.jks

    Explanation:

    • -import: Imports a certificate into the keystore.
    • -alias mykey: The alias of the key pair for which the certificate was issued.
    • -file mycert.crt: The file that contains the signed certificate.
    • -keystore mykeystore.jks: The keystore into which the certificate will be imported.
  3. Enter Keystore Password:

    • You will be prompted to enter the keystore password to access the keystore.






Please do like and subscribe to my youtube channel: https://www.youtube.com/@foalabs If you like this post please follow,share and comment

Comments

Popular posts from this blog

WebLogic migration to OCI using WDT tool

WebLogic migration to OCI using WDT tool Oracle WebLogic Deploy Tool (WDT) is an open-source project designed to simplify and streamline the management of Oracle WebLogic Server domains. With WDT, you can export configuration and application files from one WebLogic Server domain and import them into another, making it a highly effective tool for tasks like migrating on-premises WebLogic configurations to Oracle Cloud. This blog outlines a detailed step-by-step process for using WDT to migrate WebLogic resources and configurations. Supported WLS versions Why Use WDT for Migration? When moving Oracle WebLogic resources from an on-premises environment to Oracle Cloud (or another WebLogic Server), WDT provides an efficient and reliable approach to: Discover and export domain configurations and application binaries. Create reusable models and archives for deployment in a target domain. Key Pre-Requisites Source System: An Oracle WebLogic Server with pre-configured resources such as: Applica...

How to Validate TDE Wallet Password in Oracle Database

How to Validate TDE Wallet Password in Oracle Database Validating the Transparent Data Encryption (TDE) wallet password is crucial, especially when ensuring that the password is correct without using the OPEN or CLOSE commands in the database. This blog post explains a straightforward method to validate the TDE password using the mkstore utility. Steps to Validate TDE Wallet Password Follow these steps to validate the TDE wallet password: Step 1: Copy the Keystore/Wallet File Navigate to your existing TDE wallet directory. Copy only the ewallet.p12 file to a new directory. If a cwallet.sso file exists, do not copy it . The absence of cwallet.sso ensures that the wallet does not use auto-login, forcing the utility to prompt for the password. Step 2: Validate Using mkstore Use the mkstore utility to check the contents of the wallet file. The mkstore utility will prompt you for the TDE wallet password, allowing you to validate its correctness. Command Syntax To display the conten...

How to Create macOS Catalina ISO File

  How to Create macOS Catalina ISO File Please note these steps need to be performed on a Apple Mac System to generate an iso. Steps: 1) Download macOS Catalina From App Store or Apple download 2) Please note once you download it will be in dmg format. 3) Open Terminal in MAC.  from the top-right corner open up Spotlight.  Type in Terminal and hit Enter. 4)  Mount it to your macOS hdiutil attach /tmp/Catalina.dmg -noverify -mountpoint /Volumes/Catalina 5) Create macOS Catalina Installer sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/Catalina --nointeraction 6) Unmount Catalina Disk hdiutil detach /volumes/Install\ macOS\ Catalina 7) Convert the DMG file to an ISO file hdiutil convert /tmp/Catalina.dmg -format UDTO -o ~/Desktop/Catalina.cdr 8) Rename and Move to Desktop mv ~/Desktop/Catalina.cdr ~/Desktop/Catalina.iso Now we can use this iso on any system and install on virtual machines.