| 1 |
PKCS#1 v1.5 (RSA) |
| 2 |
================= |
| 3 |
|
| 4 |
An old but still solid digital signature scheme based on RSA. |
| 5 |
|
| 6 |
It is more formally called ``RSASSA-PKCS1-v1_5`` |
| 7 |
in `Section 8.2 of RFC8017`__. |
| 8 |
|
| 9 |
The following example shows how a *private* RSA key (loaded from a file) |
| 10 |
can be used to compute the signature of a message:: |
| 11 |
|
| 12 |
>>> from Crypto.Signature import pkcs1_15 |
| 13 |
>>> from Crypto.Hash import SHA256 |
| 14 |
>>> from Crypto.PublicKey import RSA |
| 15 |
>>> |
| 16 |
>>> message = b'To be signed' |
| 17 |
>>> key = RSA.import_key(open('private_key.der').read()) |
| 18 |
>>> h = SHA256.new(message) |
| 19 |
>>> signature = pkcs1_15.new(key).sign(h) |
| 20 |
|
| 21 |
At the other end, the receiver can verify the signature (and therefore |
| 22 |
the authenticity of the message) using the matching *public* RSA key:: |
| 23 |
|
| 24 |
>>> key = RSA.import_key(open('public_key.der').read()) |
| 25 |
>>> h = SHA256.new(message) |
| 26 |
>>> try: |
| 27 |
>>> pkcs1_15.new(key).verify(h, signature) |
| 28 |
>>> print "The signature is valid." |
| 29 |
>>> except (ValueError, TypeError): |
| 30 |
>>> print "The signature is not valid." |
| 31 |
|
| 32 |
.. __: https://tools.ietf.org/html/rfc8017 |
| 33 |
|
| 34 |
.. automodule:: Crypto.Signature.pkcs1_15 |
| 35 |
:members: |