Posts Creating and Converting Keys for a Valid SSL Certificate
Post
Cancel

Creating and Converting Keys for a Valid SSL Certificate

Creating and Converting Keys for a Valid SSL Certificate

Securing your website with SSL/TLS encryption requires a valid SSL certificate. This tutorial will guide you through the process of creating a Certificate Signing Request (CSR), generating a private key, obtaining a certificate, and converting keys to ensure your SSL certificate works properly.

Step 1: Generate a Private Key

The first step in creating a valid SSL certificate is generating a private key. This key is used to encrypt data and should be kept secure. Run the following command to generate a 2048-bit RSA private key:

1
openssl genrsa -out privkey.pem 2048

This will create a file named privkey.pem that contains your private key.

Step 2: Create a Certificate Signing Request (CSR)

After generating the private key, you need to create a CSR. The CSR is sent to a Certificate Authority (CA) to request an SSL certificate. Run the following command, replacing the placeholder values with your actual information:

1
openssl req -new -key privkey.pem -out mycert.csr -subj "/C=BR/ST=YourState/L=YourCity/O=YourOrganization/OU=YourUnit/CN=yourdomain.com"

The CSR file (mycert.csr) will be generated based on the provided information, such as country, state, city, organization, and domain name.

Step 3: Submit the CSR to a Certificate Authority

Next, submit the mycert.csr to a CA of your choice (e.g., Let’s Encrypt, Comodo, DigiCert) to request an SSL certificate. After the CA processes your request, they will provide you with the necessary certificate files, including the domain certificate and sometimes intermediate certificates.

Step 4: Combine Certificates to Create a Full Chain

To ensure your certificate works correctly across all browsers, you need to combine your domain certificate with the intermediate and root certificates provided by the CA. This combined file is known as the fullchain.pem.

Use the following command to concatenate the domain certificate (mycert.pem), intermediate certificate, and root certificate into a single file:

1
cat mycert.pem intermediate.pem root.pem > fullchain.pem

This will create the fullchain.pem file, which includes all the necessary certificates for validation.

Step 5: Convert the Private Key to PEM Format (if needed)

If you need to convert the private key to PEM format, use the following command:

1
openssl rsa -in privkey.pem -out privkey-converted.pem

This will convert your private key to the correct PEM format if required.

Step 6: Verify the Full Chain

After generating the fullchain.pem, verify its contents using OpenSSL to ensure the chain is complete and valid:

1
openssl verify -CAfile fullchain.pem mycert.pem

This command checks whether the certificate is valid and trusted by the intermediate and root certificates in the fullchain.pem file.

Conclusion

By following these steps, you can generate the private key, create a CSR, obtain a valid SSL certificate, and convert or verify the keys to ensure the certificate is correctly set up. These steps are essential to securing your website with SSL/TLS encryption.


References:

This post is licensed under CC BY 4.0 by the author.