How to show the actual value of a signature using the RSA library in Python?
<p>I'm using the <a href="https://stuvel.eu/python-rsa-doc/index.html" rel="nofollow">RSA library</a> to check a digital signature using the Public Key as follows:</p>

<pre><code>rsa.verify(message, sig, key)
</code></pre>

<p>The function works as expected however, for incorrect cases the library prints out  </p>

<pre><code>rsa.pkcs1.VerificationError: Verification failed
</code></pre>

<p>I want to see the actual calculated value, so that I can compare it to the expected value. Is there a way to print that without tweaking the internals of the library?</p>

<p>Using the <code>verify()</code> method as a template:  </p>

<pre><code>from rsa import common, core, transform

keylength = common.byte_size(base)
decrypted = core.decrypt_int(sig, exp, base)
clearsig = transform.int2bytes(decrypted, keylength)
</code></pre>

<p>This is with the assumption that your signature is given as <code>sig</code>, the modulus and exp of the public key are <code>base</code> and <code>exp</code> respectively.  </p>

<p>Last thing to note is that your hash might include padding in the beginning. As I used SHA-256, I had to look at the last 32 bytes of <code>clearsig</code>.</p>

python rsa digital-signature