Cryptography Tutorials - Herong's Tutorial Examples - Version 5.35, by Dr. Herong Yang
"OpenSSL" Self-Signing CA's Public Key
This section provides a tutorial example on how to use OpenSSL to generate a self-signed certificate for your public key as CA certificate.
As you know, my key file actually contains a pair of keys: my private key and my public key. My private key will be used only by myself to sign any documents. My public key will be used by whoever receives the document signed by me to verify the signature.
To give out my public key, I need to be put it into a certificate with my name, and signed by my own private key. This process is call generating a self-signed public key certificate. OpenSSL can do this in a single command "openssl req -new -x509" as shown in the following command window session:
>openssl req -new -key herong.key -x509 -days 3650 -out herong.crt -config openssl.cnf Enter pass phrase for herong.key: keypass 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) [CA]: State or Province Name (full name) [HY State]: Locality Name (eg, city) [HY City]: Organization Name (eg, company) [HY Company]: Organizational Unit Name (eg, section) [HY Unit]: Common Name (eg, YOUR name) [Herong Yang]: Email Address [herongyang.com]: >type herong.crt -----BEGIN CERTIFICATE----- MIIElzCCA3+gAwIBAgIBADANBgkqhkiG9w0BAQQFADCBkzELMAkGA1UE... ... KqbxyZS65093ifrC0kmfNCY3cq+vBqdMvpV9 -----END CERTIFICATE-----
Here is what happened:
Want to see some details about my self-signed certificate? Run the "openssl rsa" as shown below:
>openssl x509 -in herong.crt -noout -text Certificate: Data: Version: 3 (0x2) Serial Number: 0 (0x0) Signature Algorithm: md5WithRSAEncryption Issuer: C=CA, ST=HY State, L=HY City, O=HY Company, OU=HY Unit, CN=Herong Yang/emailAddress=herongyang.com Validity Not Before: Apr 1 14:07:29 2007 GMT Not After : Mar 29 14:07:29 2017 GMT Subject: C=CA, ST=HY State, L=HY City, O=HY Company, OU=HY Unit, CN=Herong Yang/emailAddress=herongyang.com Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public Key: (2048 bit) Modulus (2048 bit): 00:ba:a3:a2:d1:ab:9b:9f:26:e6:b5:79:... ... Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 36:7C:F4:4A:A4:9B:C9:B5:C5:F7:09:3F:31:1... X509v3 Authority Key Identifier: keyid:36:7C:F4:4A:A4:9B:C9:B5:C5:F7:09:3... DirName:/C=CA/ST=HY State/L=HY City /O=HY Company/OU=HY Unit/CN=Herong Yang /emailAddress=herongyang.com serial:00 X509v3 Basic Constraints: CA:TRUE Signature Algorithm: md5WithRSAEncryption aa:40:06:c0:cb:28:74:b1:1e:c2:a2:89:4f:8d:1e:9c:... ...
Notice that a default serial number, 0, is used when self-signing your own CA public key certificate.
As a CA, now I have my private key and my public key certificate. I am ready to sign anything. The next section describes how someone else can use "keytool" to generated a public key and ask me to sign it.
Note that if you use the "openssl req -new -x509" command without the "-config openssl.cnf" option, "OpenSSL" will give you an error like this:
>openssl req -new -key herong.key -x509 -out herong.crt -days 3650 Unable to load config info Enter pass phrase for herong.key: unable to find 'distinguished_name' in config problems making Certificate Request 2252:error:0E06D06A:configuration file routines: NCONF_get_string:no conf or environment variable:conf_lib.c:325:
Last update: 2013.
Table of Contents