blob: 61121e08c95e96255a85f92a33d29a7b95732692 [file] [log] [blame]
Sybren A. Stüvelaa28c042011-07-30 23:48:00 +02001Usage
2==================================================
3
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +02004This section describes the usage of the Python-RSA module.
Sybren A. Stüvelaa28c042011-07-30 23:48:00 +02005
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +02006Before you can use RSA you need keys. You will receive a private key
7and a public key.
8
9.. note::
10
11 The private key is called *private* for a reason. Never share this
12 key with anyone.
13
Sybren A. Stüveld92b6672011-07-31 17:44:44 +020014The public key is used for encypting a message such that it can only
15be read by the owner of the private key. As such it's also referred to
16as the *encryption key*. Decrypting a message can only be done using
17the private key, hence it's also called the *decryption key*.
18
19The private key is used for signing a message. With this signature and
20the public key, the receiver can verifying that a message was signed
21by the owner of the private key, and that the message was not modified
22after signing.
23
24Generating keys
25--------------------------------------------------
26
27You can use the :py:func:`rsa.newkeys` function to create a keypair.
28Alternatively you can use :py:func:`rsa.PrivateKey.load_pkcs1` and
29:py:func:`rsa.PublicKey.load_pkcs1` to load keys from a file.
30
31Generating a keypair may take a long time, depending on the number of
32bits required. The number of bits determines the cryptographic
33strength of the key, as well as the size of the message you can
34encrypt. If you don't mind having a slightly smaller key than you
35requested, you can pass ``accurate=False`` to speed up the key
36generation process.
37
38These are some timings from my netbook (Linux 2.6, 1.6 GHz Intel Atom
39N270 CPU, 2 GB RAM):
40
41+----------------+------------------+
42| Keysize (bits) | Time to generate |
43+================+==================+
44| 32 | 0.01 sec. |
45+----------------+------------------+
46| 64 | 0.03 sec. |
47+----------------+------------------+
48| 96 | 0.04 sec. |
49+----------------+------------------+
50| 128 | 0.08 sec. |
51+----------------+------------------+
52| 256 | 0.27 sec. |
53+----------------+------------------+
54| 384 | 0.93 sec. |
55+----------------+------------------+
56| 512 | 1.21 sec. |
57+----------------+------------------+
58| 1024 | 7.93 sec. |
59+----------------+------------------+
60| 2048 | 132.97 sec. |
61+----------------+------------------+
62
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020063
64Encryption and decryption
65--------------------------------------------------
66
Sybren A. Stüveld92b6672011-07-31 17:44:44 +020067To encrypt or decrypt a message, use :py:func:`rsa.encrypt` resp.
68:py:func:`rsa.decrypt`. Let's say that Alice wants to send a message
69that only Bob can read.
70
71#. Bob generates a keypair, and gives the public key to Alice. This is
72 done such that Alice knows for sure that the key is really Bob's
73 (for example by handing over a USB stick that contains the key).
74
75#. Alice writes a message
76
77#. Alice encrypts the message using Bob's public key, and sends the
78 encrypted message.
79
80#. Bob receives the message, and decrypts it with his private key.
81
82Since Bob kept his private key *private*, Alice can be sure that he is
83the only one who can read the message. Bob does *not* know for sure
84that it was Alice that sent the message, since she didn't sign it.
85
86
87Low-level operations
88++++++++++++++++++++++++++++++
89
90The core RSA algorithm operates on large integers. These operations
91are considered low-level and are supported by the
92:py:func:`rsa.core.encrypt_int` and :py:func:`rsa.core.decrypt_int`
93functions.
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020094
95Signing and verification
96--------------------------------------------------
97
98
99Working with big files
100--------------------------------------------------
101
102
Sybren A. Stüvelaa28c042011-07-30 23:48:00 +0200103