How to generate a digital signature using OpenSSL

The first step is to generate a hash of the message file:

$ openssl dgst -sha256 message.txt 
SHA256(message.txt)=
eb96d1f89812bf4967d9fb4ead128c3b787272b7be21dd2529278db1128d559c  

Both hash generation and signing can be done in a single step, as shown here. Note that privatekey.pem is generated in the steps provided previously:

$ openssl dgst -sha256 -sign privatekey.pem -out signature.bin message.txt  

Now, let's display the directory showing the relevant files:

$ ls -ltr 
total 36
-rw-rw-r-- 1 drequinox drequinox 14 Sep 21 05:54 message.txt -rw-rw-r-- 1 drequinox drequinox 32 Sep 21 05:57 message.bin -rw-rw-r-- 1 drequinox drequinox 45 Sep 21 06:00 message.b64 -rw-rw-r-- 1 drequinox drequinox 32 Sep 21 06:16 message.ptx -rw-rw-r-- 1 drequinox drequinox 916 Sep 21 06:28 privatekey.pem -rw-rw-r-- 1 drequinox drequinox 272 Sep 21 06:30 publickey.pem -rw-rw-r-- 1 drequinox drequinox 128 Sep 21 06:43 message.rsa -rw-rw-r-- 1 drequinox drequinox 14 Sep 21 06:49 message.dec -rw-rw-r-- 1 drequinox drequinox 128 Sep 21 07:05 signature.bin

Let's look at the contents of signature.bin by executing the following command:

$ cat signature.bin

Executing this command will give the following output:

In order to verify the signature, the following operation can be performed:

$ openssl dgst -sha256 -verify publickey.pem -signature 
signature.bin message.txt
Verified OK

Similarly, if some other signature file which is not valid is used, the verification will fail, as shown here:

$ openssl dgst -sha256 -verify publickey.pem -signature someothersignature.bin message.txt
Verification Failure  

Next, an example is presented that shows how OpenSSL can be used to perform ECDSA-related operations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.18.104.213