Sunday 3 April 2022

openSSL: Generate ssl certificate

In this post, I am going to explain how to generate ssl certificate

 

Step 1: Open terminal and execute below command.

 

openssl req -newkey rsa:2048 -nodes -keyout domain.key -x509 -days 500 -out domain.crt

$openssl req -newkey rsa:2048 -nodes -keyout domain.key -x509 -days 500 -out domain.crt
Generating a 2048 bit RSA private key
.+++
...........................+++
writing new private key to 'domain.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) []:in
State or Province Name (full name) []:karnataka
Locality Name (eg, city) []:Bangalore
Organization Name (eg, company) []:self-learning-java
Organizational Unit Name (eg, section) []:tutorials
Common Name (eg, fully qualified host name) []:self-learning-java.com
Email Address []:self-learning-java@123.com
$

 

Above command prompts some information that is used to while generating the certificate.

 

Once the command executed successfully, it generate two files ‘domain.crt’ and ‘domain.key’

$ls
domain.crt	domain.key

 


Execute below command to view the content of domain.crt in plain text.

openssl x509 -text -noout -in domain.crt

$openssl x509 -text -noout -in domain.crt
Certificate:
    Data:
        Version: 1 (0x0)
        Serial Number: 10603830801797846590 (0x93285feec781963e)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=in, ST=karnataka, L=Bangalore, O=self-learning-java, OU=tutorials, CN=self-learning-java.com/emailAddress=self-learning-java@123.com
        Validity
            Not Before: Mar 30 11:38:31 2022 GMT
            Not After : Aug 12 11:38:31 2023 GMT
        Subject: C=in, ST=karnataka, L=Bangalore, O=self-learning-java, OU=tutorials, CN=self-learning-java.com/emailAddress=self-learning-java@123.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:bf:7c:2a:d2:8c:f2:d0:4a:ce:dd:c3:7e:d6:e9:
                    5c:31:5f:f8:ce:0c:f9:c0:3a:b3:7b:4b:1b:f7:72:
                    48:d2:c1:66:e1:84:47:79:d0:db:f8:6c:fb:43:6a:
                    79:8d:0f:b2:5e:27:1d:22:a2:eb:b6:d7:d3:a0:c6:
                    16:b2:eb:72:45:ce:43:53:a3:ea:3d:59:96:d4:74:
                    d0:df:79:88:c7:35:a5:13:8c:3e:d0:e9:e9:1b:99:
                    08:35:0d:59:40:05:a3:0f:71:ab:b4:f0:40:f8:5d:
                    a1:2a:d1:b7:4e:9a:bc:e3:76:b6:98:43:1a:e5:31:
                    37:f8:42:71:72:38:bb:9a:94:53:2a:a9:63:18:c8:
                    48:00:03:c2:90:ca:49:de:a1:3e:82:db:af:90:e7:
                    5b:21:6d:ae:16:4f:bc:1a:74:97:c7:cb:d7:71:2c:
                    0c:10:b8:77:91:ee:1f:45:6c:8c:55:59:25:33:ec:
                    e5:2c:35:3f:c0:3b:86:28:7d:09:54:5c:1e:8a:a3:
                    b5:b3:ab:d7:21:49:2e:d8:ea:20:5d:c4:17:9f:2e:
                    08:af:c3:02:35:90:79:a7:9b:f2:1d:f6:df:62:d9:
                    9b:b0:df:e0:fc:cd:6e:56:ab:fc:86:f5:72:f5:10:
                    e1:dc:bb:c6:7e:e5:b4:fe:45:3b:f6:fe:74:d3:4e:
                    c4:c3
                Exponent: 65537 (0x10001)
    Signature Algorithm: sha256WithRSAEncryption
         46:6b:5c:b3:f5:ee:f9:6e:5f:cd:9b:c2:53:2e:00:64:42:bf:
         50:32:23:34:5c:4e:0c:30:e5:5d:a2:68:2b:4a:bb:5f:d1:3e:
         91:09:9d:de:49:6f:a9:6d:55:59:a2:52:a8:0c:e4:b6:83:2c:
         2c:f5:50:85:26:ce:87:52:5a:23:e4:d3:00:48:b0:23:40:e0:
         04:f8:94:c7:fc:f6:d1:2b:f6:2f:0d:fe:1b:f4:66:ba:7d:52:
         eb:80:ac:c3:19:4b:7f:39:db:60:c1:f2:2e:16:05:ac:81:b7:
         ec:14:57:a0:29:45:37:e4:70:ff:5f:3e:15:4a:97:eb:e6:74:
         9d:75:1a:cf:3d:41:3e:8b:94:ac:11:7e:9f:ef:50:9f:70:a4:
         b9:e2:d4:67:9a:ca:20:4d:de:9b:75:3e:1d:83:73:4b:63:02:
         4b:3e:da:7b:ec:30:b4:25:2f:12:55:96:ea:54:02:c4:cb:9a:
         b9:f0:e2:c8:e1:35:3e:72:58:96:c3:14:3e:f7:71:e9:9a:84:
         10:5b:eb:c0:85:49:8f:83:b3:32:6e:28:d0:ef:31:cb:8e:ca:
         c3:5a:73:32:47:53:fb:be:45:d4:82:c6:80:5f:74:f7:f3:83:
         58:ed:0e:0f:d2:e1:80:d4:47:ff:0c:14:c9:4d:19:5e:37:a9:
         51:f1:1a:32
$

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment