Sybren A. Stüvel | 3cf7e45 | 2011-01-09 12:29:49 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | '''Re-encryption demonstration |
| 4 | |
| 5 | This little program shows how to re-encrypt crypto from versions older than 2.0. |
| 6 | Those versions were inherently insecure, and version 2.0 solves those |
| 7 | insecurities. This did result in a different crypto format, so it's not backward |
| 8 | compatible. Use this program as a demonstration on how to re-encrypt your |
| 9 | files/passwords/whatevers into the new format. |
| 10 | ''' |
| 11 | |
| 12 | import sys |
| 13 | import rsa |
| 14 | from rsa import _version133 as insecure |
| 15 | |
| 16 | (pub, priv) = rsa.newkeys(64) |
| 17 | |
| 18 | # Construct the encrypted content. You'd typically read an encrypted file or |
| 19 | # stream here. |
| 20 | cleartext = 'Give me more cowbell' |
| 21 | old_crypto = insecure.encrypt(cleartext, pub) |
| 22 | print 'Old crypto:', old_crypto |
| 23 | print |
| 24 | |
| 25 | # Decrypt and re-encrypt the contents to make it compatible with the new RSA |
| 26 | # module. |
| 27 | decrypted = insecure.decrypt(old_crypto, priv) |
| 28 | new_crypto = rsa.encrypt(decrypted, pub) |
| 29 | |
| 30 | print 'New crypto:', new_crypto |
| 31 | print |
| 32 | |