Generating, Signing and Verifying Digital Signature
<p>So here's a question from my project.</p>

<blockquote>
  <p>In this task, we will use OpenSSL to generate digital signatures. Please prepare a file (example.txt) of any size. Also prepare an RSA public/private key pair. Then do the following:</p>
  
  <ol>
  <li>Sign the SHA256 hash of example.txt; save the output in example.sha256.</li>
  <li>Verify the digital signature in example.sha256.</li>
  <li>Slightly modify example.txt, and verify the digital signature again.</li>
  </ol>
  
  <p>Please describe how you performed the above three operations (e.g., the exact commands that you used, etc.). Describe what you observed and explain your observations. Please also explain why digital signatures are useful in general.</p>
</blockquote>

<p>So, I do the following.</p>

<p><strong>1.Create private/public key pair</strong></p>

<pre><code>openssl genrsa -out private.pem 1024
</code></pre>

<p><strong>2. Extracting Public key.</strong></p>

<pre><code>openssl rsa -in private.pem -out public.pem -outform PEM -pubout
</code></pre>

<p><strong>3. Create hash of the data.</strong></p>

<pre><code>echo 'data to sign' &gt; example.txt

openssl dgst -sha256 &lt; example.txt &gt; hash
</code></pre>

<p><strong>4. Sign the hash using Private key to a file called example.sha256</strong></p>

<pre><code>openssl rsautl -sign -inkey private.pem -keyform PEM -in hash  &gt; example.sha256
</code></pre>

<p><strong>5. Verify the file (example.txt)and the digital signature (example.sha256)</strong></p>

<pre><code>openssl dgst -sha256 -verify public.pem -signature example.sha256 example.txt
</code></pre>

<p>After doing all this, I get an error message saying "<strong>Verification Failure</strong>"</p>

<p>Please correct me if I went wrong somewhere.</p>