Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 1 | .. hazmat:: |
| 2 | |
| 3 | RSA |
| 4 | === |
| 5 | |
| 6 | .. currentmodule:: cryptography.hazmat.primitives.asymmetric.rsa |
| 7 | |
| 8 | `RSA`_ is a `public-key`_ algorithm for encrypting and signing messages. |
| 9 | |
| 10 | .. class:: RSAPrivateKey(p, q, private_exponent, public_exponent, modulus) |
Alex Gaynor | 14971b7 | 2014-02-13 12:56:14 -0800 | [diff] [blame] | 11 | |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 12 | .. versionadded:: 0.2 |
| 13 | |
| 14 | An RSA private key is required for decryption and signing of messages. |
| 15 | |
Alex Stapleton | b232d74 | 2014-02-08 14:18:59 +0000 | [diff] [blame] | 16 | You should use |
| 17 | :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.generate` |
| 18 | to generate new keys. |
Alex Gaynor | 14971b7 | 2014-02-13 12:56:14 -0800 | [diff] [blame] | 19 | |
Alex Stapleton | be5da2d | 2014-02-07 08:15:39 +0000 | [diff] [blame] | 20 | .. warning:: |
| 21 | This method only checks a limited set of properties of its arguments. |
Alex Gaynor | 14971b7 | 2014-02-13 12:56:14 -0800 | [diff] [blame] | 22 | Using an RSA private key that you do not trust or with incorrect |
| 23 | parameters may lead to insecure operation, crashes, and other undefined |
| 24 | behavior. We recommend that you only ever load private keys that were |
| 25 | generated with software you trust. |
Alex Stapleton | be5da2d | 2014-02-07 08:15:39 +0000 | [diff] [blame] | 26 | |
Alex Stapleton | b232d74 | 2014-02-08 14:18:59 +0000 | [diff] [blame] | 27 | |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 28 | This class conforms to the |
| 29 | :class:`~cryptography.hazmat.primitives.interfaces.RSAPrivateKey` |
| 30 | interface. |
| 31 | |
Alex Gaynor | 14971b7 | 2014-02-13 12:56:14 -0800 | [diff] [blame] | 32 | :raises TypeError: This is raised when the arguments are not all integers. |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 33 | |
Alex Gaynor | a9d802a | 2014-02-13 12:57:57 -0800 | [diff] [blame] | 34 | :raises ValueError: This is raised when the values of ``p``, ``q``, |
| 35 | ``private_exponent``, ``public_exponent``, or |
| 36 | ``modulus`` do not match the bounds specified in |
| 37 | :rfc:`3447`. |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 38 | |
Alex Stapleton | b232d74 | 2014-02-08 14:18:59 +0000 | [diff] [blame] | 39 | .. classmethod:: generate(public_exponent, key_size, backend) |
| 40 | |
| 41 | Generate a new ``RSAPrivateKey`` instance using ``backend``. |
| 42 | |
| 43 | :param int public_exponent: The public exponent of the new key. |
| 44 | Usually one of the small Fermat primes 3, 5, 17, 257, 65537. If in |
| 45 | doubt you should `use 65537`_. |
| 46 | :param int key_size: The length of the modulus in bits. For keys |
| 47 | generated in 2014 this should be `at least 2048`_. (See page 41.) |
| 48 | Must be at least 512. Some backends may have additional |
| 49 | limitations. |
| 50 | :param backend: A |
| 51 | :class:`~cryptography.hazmat.backends.interfaces.RSABackend` |
| 52 | provider. |
| 53 | :return: A new instance of ``RSAPrivateKey``. |
| 54 | |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 55 | .. class:: RSAPublicKey(public_exponent, modulus) |
Alex Gaynor | 14971b7 | 2014-02-13 12:56:14 -0800 | [diff] [blame] | 56 | |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 57 | .. versionadded:: 0.2 |
| 58 | |
| 59 | An RSA public key is required for encryption and verification of messages. |
| 60 | |
| 61 | Normally you do not need to directly construct public keys because you'll |
| 62 | be loading them from a file, generating them automatically or receiving |
| 63 | them from a 3rd party. |
| 64 | |
| 65 | This class conforms to the |
| 66 | :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey` |
| 67 | interface. |
| 68 | |
Alex Gaynor | 14971b7 | 2014-02-13 12:56:14 -0800 | [diff] [blame] | 69 | :raises TypeError: This is raised when the arguments are not all integers. |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 70 | |
Alex Gaynor | a9d802a | 2014-02-13 12:57:57 -0800 | [diff] [blame] | 71 | :raises ValueError: This is raised when the values of ``public_exponent`` |
| 72 | or ``modulus`` do not match the bounds specified in |
| 73 | :rfc:`3447`. |
Alex Stapleton | 940eee2 | 2014-02-05 20:25:30 +0000 | [diff] [blame] | 74 | |
| 75 | .. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) |
| 76 | .. _`public-key`: https://en.wikipedia.org/wiki/Public-key_cryptography |
Alex Stapleton | b232d74 | 2014-02-08 14:18:59 +0000 | [diff] [blame] | 77 | .. _`use 65537`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html |
| 78 | .. _`at least 2048`: http://www.ecrypt.eu.org/documents/D.SPA.20.pdf |