Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 1 | Upgrading from older versions |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 2 | ============================= |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 3 | |
| 4 | Previous versions of Python-RSA were less secure than the current |
| 5 | version. In order to be able to gradually upgrade your software, those |
Sybren A. Stüvel | 8085da5 | 2016-01-27 14:40:48 +0100 | [diff] [blame] | 6 | old versions will be available until Python-RSA 4.0. |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 7 | |
| 8 | To use version 1.3.3, use this:: |
| 9 | |
| 10 | import rsa._version133 as rsa |
| 11 | |
| 12 | And to use version 2.0, use this:: |
| 13 | |
| 14 | import rsa._version200 as rsa |
| 15 | |
| 16 | You can import all three versions at the same time. This allows you to |
| 17 | use an old version to decrypt your messages, and a new version to |
| 18 | re-encrypt them:: |
| 19 | |
| 20 | import rsa._version200 as rsa200 |
| 21 | import rsa # this imports version 3.0 |
| 22 | |
| 23 | decrypted = rsa200.decrypt(old_crypto, version_200_private_key) |
| 24 | new_crypto = rsa.encrypt(decrypted, version_3_public_key) |
| 25 | |
| 26 | Those import statements *will create warnings* as they import much |
| 27 | less secure code into your project. |
| 28 | |
Sybren A. Stüvel | 8085da5 | 2016-01-27 14:40:48 +0100 | [diff] [blame] | 29 | .. warning:: |
| 30 | |
| 31 | These modules are included to allow upgrading to the latest version |
| 32 | of Python-RSA, and not as a way to keep using those old versions. |
| 33 | They will be removed in version 4.0. |
| 34 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 35 | The random padding introduced in version 3.0 made things much more |
| 36 | secure, but also requires a larger key to encrypt the same message. |
| 37 | You can either generate a new key with :py:func:`rsa.newkeys`, or use |
| 38 | :py:func:`rsa.bigfile.encrypt_bigfile` to encrypt your files. |
| 39 | |
| 40 | Converting keys |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 41 | --------------- |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 42 | |
| 43 | Version 3.0 introduced industrial standard RSA keys according to |
| 44 | PKCS#1. The old keys were just dictionaries. To convert a key from an |
| 45 | older version of Python-RSA, use the following:: |
| 46 | |
| 47 | import rsa |
| 48 | |
| 49 | # Load the old key somehow. |
| 50 | old_pub_key = { |
| 51 | 'e': 65537, |
| 52 | 'n': 31698122414741849421263704398157795847591L |
| 53 | } |
| 54 | |
| 55 | old_priv_key = { |
| 56 | 'd': 7506520894712811128876594754922157377793L, |
| 57 | 'p': 4169414332984308880603L, |
| 58 | 'q': 7602535963858869797L |
| 59 | } |
| 60 | |
| 61 | # Create new key objects like this: |
| 62 | pub_key = rsa.PublicKey(n=old_pub_key['n'], e=old_pub_key['e']) |
| 63 | |
| 64 | priv_key = rsa.PrivateKey(n=old_pub_key['n'], e=old_pub_key['e'], |
| 65 | d=old_priv_key['d'], p=old_priv_key['p'], q=old_priv_key['q']) |
| 66 | |
| 67 | |
| 68 | # Or use this shorter notation: |
| 69 | pub_key = rsa.PublicKey(**old_pub_key) |
| 70 | |
| 71 | old_priv_key.update(old_pub_key) |
| 72 | priv_key = rsa.PrivateKey(**old_priv_key) |
| 73 | |