Debian Codegraph @

Doc/src/cipher/oaep.rst

raw
1 .. _rsa_oaep:
2
3 PKCS#1 OAEP (RSA)
4 =================
5
6 PKCS#1 OAEP is an asymmetric cipher based on RSA and the OAEP padding.
7 It is described in `RFC8017 <https://tools.ietf.org/html/rfc8017>`_
8 where it is called ``RSAES-OAEP``.
9
10 It can only encrypt messages slightly shorter than the RSA modulus (a few
11 hundred bytes).
12
13 The following example shows how you encrypt data by means of
14 the recipient's **public key** (here assumed to be
15 available locally in a file called ``public.pem``)::
16
17 >>> from Crypto.Cipher import PKCS1_OAEP
18 >>> from Crypto.PublicKey import RSA
19 >>>
20 >>> message = b'You can attack now!'
21 >>> key = RSA.importKey(open('public.pem').read())
22 >>> cipher = PKCS1_OAEP.new(key)
23 >>> ciphertext = cipher.encrypt(message)
24
25 The recipient uses its own **private key** to decrypt the message.
26 We assume the key is stored in a file called ``private.pem``::
27
28 >>> key = RSA.importKey(open('private.pem').read())
29 >>> cipher = PKCS1_OAEP.new(key)
30 >>> message = cipher.decrypt(ciphertext)
31
32 .. warning::
33 PKCS#1 OAEP does not guarantee authenticity of the message you decrypt.
34 Since the public key is not secret, everybody could have created
35 the encrypted message.
36 Asymmetric encryption is typically paired with a digital signature.
37
38 .. note::
39 This module does not generate nor load RSA keys.
40 Refer to the :mod:`Crypto.PublicKey.RSA` module.
41
42 .. automodule:: Crypto.Cipher.PKCS1_OAEP
43 :members: