Openssl Command Generate Symmetric Key

The Most Common OpenSSL Commands. One of the most versatile SSL tools is OpenSSL which is an open source implementation of the SSL protocol. There are versions of OpenSSL for nearly every platform, including Windows, Linux, and Mac OS X. OpenSSL is commonly used to create the CSR and private key for many different platforms, including Apache. Demo of Symmetric Key Encryption using OpenSSL. The following is an example of using OpenSSL in Ubuntu Linux to perform symmetric key encryption. DES with ECB mode of operation is used. I have a similar demo of OpenSSL for DES encryption as a screencast. Also I have some different examples of encryption in my article introducing OpenSSL.

  • To use OpenSSL to generate binary key material and encrypt it for import into AWS KMS Use the following command to generate a 256-bit symmetric key and save it in a file named PlaintextKeyMaterial.bin.
  • How to Generate a Symmetric Key by Using the dd Command. A key is needed to encrypt files and to generate the MAC of a file. The key should be derived from a random pool of numbers. If your site has a random number generator, use the generator. Otherwise, you can use the dd command with the Solaris /dev/urandom device as input.
  • PKCS#8 files are self-describing, and PKCS#8 private key files contain the public key, so a single command can output all the public properties for any private key. WARNING: By default OpenSSL's command line tool will output the value of the private key, even when you ask for it to output the public metadata; the -noout parameter suppresses this.
  • The num argument for openssl rand is interpreted as number of bytes, not number of bits. An AES-128 expects a key of 128 bit, 16 byte. To generate such a key, use OpenSSL as: openssl rand 16 myaes.key AES-256 expects a key of 256 bit, 32 byte.

How to Generate a Symmetric Key byUsing the dd Command

A key is needed to encrypt files and to generate the MAC of a file.The key should be derived from a random pool of numbers.

If your site has a random number generator,use the generator. Otherwise, you can use the dd commandwith the Solaris /dev/urandom device as input. For moreinformation, see the dd(1M) manpage.

  1. Determine the key length that your algorithm requires.

    1. Listthe available algorithms.


    2. Determine the key length in bytes to pass to the dd command.

      Divide the minimum and maximum key sizes by 8. When the minimumand maximum key sizes are different, intermediate key sizes are possible.For example, the value 8, 16, or 64 can be passed to the dd commandfor the sha1_hmac and md5_hmac functions.

  2. Generate the symmetric key.


    if=file

    Is the input file. For a random key, use the /dev/urandom file.

    of=keyfile

    Is the output file that holds the generated key.

    bs=n

    Is the key size in bytes. For the length in bytes, dividethe key length in bits by 8.

    count=n

    Is the count of the input blocks. The number for n shouldbe 1.

  3. Store your key in a protected directory.

    The key fileshould not be readable by anyone but the user.


Example 14–1 Creating a Key for the AES Algorithm

In the following example, a secret key for the AES algorithm is created.The key is also stored for later decryption. AES mechanisms use a 128-bitkey. The key is expressed as 16 bytes in the dd command.


Openssl Generate Crt And Key

Example 14–2 Creating a Key for the DES Algorithm
Openssl generate symmetric key

Use Openssl To Generate Key Pair

In the following example, a secret key for the DES algorithm is created.The key is also stored for later decryption. DES mechanisms use a 64-bit key.The key is expressed as 8 bytes in the dd command.

Openssl

Example 14–3 Creating a Key for the 3DES Algorithm

In the following example, a secret key for the 3DES algorithm is created.The key is also stored for later decryption. 3DES mechanisms use a 192-bitkey. The key is expressed as 24 bytes in the dd command.


Example 14–4 Creating a Key for the MD5 Algorithm

In the following example, a secret key for the MD5 algorithm is created.The key is also stored for later decryption. The key is expressed as 64 bytesin the dd command.