aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-12-19 16:17:45 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-12-19 16:17:45 -0800
commit78515f2b57e84586ba71ad905a1cd53c1d7cda61 (patch)
tree4afa2590f05abbebda66803be4f5fe086875c8a1
parentc663894bf48244f2f3c81ceb7d6ba2ce4518f8b3 (diff)
downloadcryptography-78515f2b57e84586ba71ad905a1cd53c1d7cda61.tar.gz
cryptography-78515f2b57e84586ba71ad905a1cd53c1d7cda61.tar.bz2
cryptography-78515f2b57e84586ba71ad905a1cd53c1d7cda61.zip
Describe key generation and key loading in the RSA docs
-rw-r--r--docs/hazmat/primitives/asymmetric/rsa.rst38
1 files changed, 37 insertions, 1 deletions
diff --git a/docs/hazmat/primitives/asymmetric/rsa.rst b/docs/hazmat/primitives/asymmetric/rsa.rst
index 7f902fff..0a25e68f 100644
--- a/docs/hazmat/primitives/asymmetric/rsa.rst
+++ b/docs/hazmat/primitives/asymmetric/rsa.rst
@@ -10,11 +10,20 @@ RSA
Generation
~~~~~~~~~~
+Unlike symmetric cryptography, where the key is typically just a random series
+of bytes, RSA keys have a complex internal structure with `specific
+mathematical properties`_.
+
.. function:: generate_private_key(public_exponent, key_size, backend)
.. versionadded:: 0.5
- Generate an RSA private key using the provided ``backend``.
+ Generates a new RSA private key using the provided ``backend``.
+ ``key_size`` describes how many bits long the key should be, larger keys
+ provide more security, currently ``1024`` and below are considered
+ breakable, and ``2048`` or ``4096`` are reasonable default key sizes for
+ new keys. The ``public_exponent`` indicates what one mathematical property
+ of the key generation will be, ``65537`` should almost always be used.
.. doctest::
@@ -42,6 +51,32 @@ Generation
the provided ``backend`` does not implement
:class:`~cryptography.hazmat.backends.interfaces.RSABackend`
+Key loading
+~~~~~~~~~~~
+
+If you already have an on-disk key in the PEM format (which are recognizable by
+the distinctive ``-----BEGIN {format}-----`` and ``-----END {format}-----``
+markers), you can load it:
+
+.. code-block:: pycon
+
+ >>> from cryptography.hazmat.primitives import serialization
+
+ >>> with open("path/to/key.pem", "rb") as key_file:
+ ... private_key = serialization.load_pem_private_key(
+ ... key_file.read(),
+ ... password=None,
+ ... backend=default_backend()
+ ... )
+
+Serialized keys may optionally be encrypted on disk using a password. In this
+example we loaded an unencrypted key, and therefore we did not provide a
+password. If the key is encrypted we can pass a ``bytes`` object as the
+``password`` argument.
+
+There is also support for :func:`loading public keys in the SSH format
+<cryptography.hazmat.primitives.serialization.load_ssh_public_key`.
+
Signing
~~~~~~~
@@ -359,6 +394,7 @@ this without having to do the math themselves.
.. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
.. _`public-key`: https://en.wikipedia.org/wiki/Public-key_cryptography
+.. _`specific mathematical properties`: https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Key_generation
.. _`use 65537`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
.. _`at least 2048`: http://www.ecrypt.eu.org/documents/D.SPA.20.pdf
.. _`OpenPGP`: https://en.wikipedia.org/wiki/Pretty_Good_Privacy