Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.18 KB

pkcs1_v1_5.rst

File metadata and controls

35 lines (27 loc) · 1.18 KB

PKCS#1 v1.5 (RSA)

An old but still solid digital signature scheme based on RSA.

It is more formally called RSASSA-PKCS1-v1_5 in Section 8.2 of RFC8017.

The following example shows how a private RSA key (loaded from a file) can be used to compute the signature of a message:

>>> from Crypto.Signature import pkcs1_15
>>> from Crypto.Hash import SHA256
>>> from Crypto.PublicKey import RSA
>>>
>>> message = b'To be signed'
>>> key = RSA.import_key(open('private_key.der').read())
>>> h = SHA256.new(message)
>>> signature = pkcs1_15.new(key).sign(h)

At the other end, the receiver can verify the signature (and therefore the authenticity of the message) using the matching public RSA key:

>>> key = RSA.import_key(open('public_key.der').read())
>>> h = SHA256.new(message)
>>> try:
>>>     pkcs1_15.new(key).verify(h, signature)
>>>     print "The signature is valid."
>>> except (ValueError, TypeError):
>>>    print "The signature is not valid."
.. automodule:: Crypto.Signature.pkcs1_15
    :members: