blob: 3381baa11c81659c9d34daf51c2a3d54945641c5 [file] [log] [blame]
Sybren A. Stüveldbea2132011-08-03 13:31:57 +02001Upgrading from older versions
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +01002=============================
Sybren A. Stüveldbea2132011-08-03 13:31:57 +02003
Sybren A. Stüvel1d14c4e2017-04-10 11:31:09 +02004From versions older than Python-RSA 4.0
5---------------------------------------
6
7Support for the VARBLOCK/bigfile format has been dropped in version 4.0, after
8being deprecated for a year. There is no alternative implementation in
9Python-RSA 4.0. If you need this, or have ideas on how to do handle encryption
10of large files securely and in a compatible way with existing standards,
11`open a ticket to discuss this`_.
12
13.. _open a ticket to discuss this:
14 https://github.com/sybrenstuvel/python-rsa/issues/new
15
16
17From versions older than Python-RSA 3.4
18---------------------------------------
19
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020020Previous versions of Python-RSA were less secure than the current
21version. In order to be able to gradually upgrade your software, those
Sybren A. Stüvel8085da52016-01-27 14:40:48 +010022old versions will be available until Python-RSA 4.0.
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020023
24To use version 1.3.3, use this::
25
26 import rsa._version133 as rsa
27
28And to use version 2.0, use this::
29
30 import rsa._version200 as rsa
31
32You can import all three versions at the same time. This allows you to
33use an old version to decrypt your messages, and a new version to
34re-encrypt them::
35
36 import rsa._version200 as rsa200
37 import rsa # this imports version 3.0
38
39 decrypted = rsa200.decrypt(old_crypto, version_200_private_key)
40 new_crypto = rsa.encrypt(decrypted, version_3_public_key)
41
42Those import statements *will create warnings* as they import much
43less secure code into your project.
44
Sybren A. Stüvel8085da52016-01-27 14:40:48 +010045.. warning::
46
47 These modules are included to allow upgrading to the latest version
48 of Python-RSA, and not as a way to keep using those old versions.
49 They will be removed in version 4.0.
50
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020051The random padding introduced in version 3.0 made things much more
52secure, but also requires a larger key to encrypt the same message.
Sybren A. Stüvel1d14c4e2017-04-10 11:31:09 +020053
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020054
55Converting keys
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +010056---------------
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020057
58Version 3.0 introduced industrial standard RSA keys according to
59PKCS#1. The old keys were just dictionaries. To convert a key from an
60older version of Python-RSA, use the following::
61
62 import rsa
63
64 # Load the old key somehow.
65 old_pub_key = {
66 'e': 65537,
67 'n': 31698122414741849421263704398157795847591L
68 }
69
70 old_priv_key = {
71 'd': 7506520894712811128876594754922157377793L,
72 'p': 4169414332984308880603L,
73 'q': 7602535963858869797L
74 }
75
76 # Create new key objects like this:
77 pub_key = rsa.PublicKey(n=old_pub_key['n'], e=old_pub_key['e'])
78
79 priv_key = rsa.PrivateKey(n=old_pub_key['n'], e=old_pub_key['e'],
80 d=old_priv_key['d'], p=old_priv_key['p'], q=old_priv_key['q'])
81
82
83 # Or use this shorter notation:
84 pub_key = rsa.PublicKey(**old_pub_key)
85
86 old_priv_key.update(old_pub_key)
87 priv_key = rsa.PrivateKey(**old_priv_key)