blob: 2875b2092d0eb009822fd3830db98c9157e9de0c [file] [log] [blame]
Alex Stapleton940eee22014-02-05 20:25:30 +00001.. hazmat::
2
3RSA
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 Gaynor14971b72014-02-13 12:56:14 -080011
Alex Stapleton940eee22014-02-05 20:25:30 +000012 .. versionadded:: 0.2
13
14 An RSA private key is required for decryption and signing of messages.
15
Alex Stapletonb232d742014-02-08 14:18:59 +000016 You should use
17 :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.generate`
18 to generate new keys.
Alex Gaynor14971b72014-02-13 12:56:14 -080019
Alex Stapletonbe5da2d2014-02-07 08:15:39 +000020 .. warning::
21 This method only checks a limited set of properties of its arguments.
Alex Gaynor14971b72014-02-13 12:56:14 -080022 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 Stapletonbe5da2d2014-02-07 08:15:39 +000026
Alex Stapletonb232d742014-02-08 14:18:59 +000027
Alex Stapleton940eee22014-02-05 20:25:30 +000028 This class conforms to the
29 :class:`~cryptography.hazmat.primitives.interfaces.RSAPrivateKey`
30 interface.
31
Alex Gaynor14971b72014-02-13 12:56:14 -080032 :raises TypeError: This is raised when the arguments are not all integers.
Alex Stapleton940eee22014-02-05 20:25:30 +000033
Alex Gaynora9d802a2014-02-13 12:57:57 -080034 :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 Stapleton940eee22014-02-05 20:25:30 +000038
Alex Stapletonb232d742014-02-08 14:18:59 +000039 .. 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 Stapleton940eee22014-02-05 20:25:30 +000055.. class:: RSAPublicKey(public_exponent, modulus)
Alex Gaynor14971b72014-02-13 12:56:14 -080056
Alex Stapleton940eee22014-02-05 20:25:30 +000057 .. 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 Gaynor14971b72014-02-13 12:56:14 -080069 :raises TypeError: This is raised when the arguments are not all integers.
Alex Stapleton940eee22014-02-05 20:25:30 +000070
Alex Gaynora9d802a2014-02-13 12:57:57 -080071 :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 Stapleton940eee22014-02-05 20:25:30 +000074
75.. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
76.. _`public-key`: https://en.wikipedia.org/wiki/Public-key_cryptography
Alex Stapletonb232d742014-02-08 14:18:59 +000077.. _`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