Debian Codegraph @

Doc/src/signature/pkcs1_pss.rst

raw
1 .. _rsa_pss:
2
3 PKCS#1 PSS (RSA)
4 ================
5
6 A probabilistic digital signature scheme based on RSA.
7
8 It is more formally called ``RSASSA-PSS``
9 in `Section 8.1 of RFC8017`__.
10
11 The following example shows how the sender can use its own *private* key
12 (loaded from a file) to create the signature of a message::
13
14 >>> from Crypto.Signature import pss
15 >>> from Crypto.Hash import SHA256
16 >>> from Crypto.PublicKey import RSA
17 >>>
18 >>> message = b'To be signed'
19 >>> key = RSA.import_key(open('privkey.der', 'rb').read())
20 >>> h = SHA256.new(message)
21 >>> signature = pss.new(key).sign(h)
22
23 At the receiver side, the matching *public* RSA key is used to verify
24 authenticity of the incoming message::
25
26 >>> key = RSA.import_key(open('pubkey.der', 'rb').read())
27 >>> h = SHA256.new(message)
28 >>> verifier = pss.new(key)
29 >>> try:
30 >>> verifier.verify(h, signature)
31 >>> print("The signature is authentic.")
32 >>> except (ValueError):
33 >>> print("The signature is not authentic.")
34
35 .. __: https://tools.ietf.org/html/rfc8017#section-8.1
36
37 .. automodule:: Crypto.Signature.pss
38 :members: