"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


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
        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
            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):
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier:
            X509v3 Authority Key Identifier:
                DirName:/C=CA/ST=HY State/L=HY City
/O=HY Company/OU=HY Unit/CN=Herong Yang

            X509v3 Basic Constraints:
    Signature Algorithm: md5WithRSAEncryption

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 

Last update: 2013.

Table of Contents

 About This Book

 Cryptography Terminology

 Cryptography Basic Concepts

 Introduction to AES (Advanced Encryption Standard)

 Introduction to DES Algorithm

 DES Algorithm - Illustrated with Java Programs

 DES Algorithm Java Implementation

 DES Algorithm - Java Implementation in JDK JCE

 DES Encryption Operation Modes

 DES in Stream Cipher Modes

 PHP Implementation of DES - mcrypt

 Blowfish - 8-Byte Block Cipher

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 Introduction of RSA Algorithm

 RSA Implementation using java.math.BigInteger Class

 Introduction of DSA (Digital Signature Algorithm)

 Java Default Implementation of DSA

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Cipher - Public Key Encryption and Decryption

 MD5 Mesasge Digest Algorithm

 SHA1 Mesasge Digest Algorithm

 OpenSSL Introduction and Installation

 OpenSSL Generating and Managing RSA Keys

 OpenSSL Managing Certificates

 OpenSSL Generating and Signing CSR

 OpenSSL Validating Certificate Path

 "keytool" and "keystore" from JDK

"OpenSSL" Signing CSR Generated by "keytool"

 "OpenSSL" Acting as a CA (Certificate Authority)

 "OpenSSL" Generating CA's Private Key

"OpenSSL" Self-Signing CA's Public Key

 "keytool" Generating Maria's Private Key

 "keytool" Generating Maria's CSR

 "OpenSSL" Signing Maria's CSR

 "OpenSSL" Managing Serial Numbers when Signing CSR

 "keytool" Importing CA's Own Certificate

 ""keytool" Importing Maria's Certificate Signed by CA

 Migrating Keys from "keystore" to "OpenSSL" Key Files

 Certificate X.509 Standard and DER/PEM Formats

 Migrating Keys from "OpenSSL" Key Files to "keystore"

 Using Certificates in IE (Internet Explorer)

 Using Certificates in Firefox

 Using Certificates in Google Chrome

 Outdated Tutorials


 PDF Printing Version