blob: 4bb134a2da1caa825e293d021eca8bebf97949f2 [file] [log] [blame]
Sybren A. Stüvel3cf7e452011-01-09 12:29:49 +01001#!/usr/bin/env python
2
3'''Re-encryption demonstration
4
5This little program shows how to re-encrypt crypto from versions older than 2.0.
6Those versions were inherently insecure, and version 2.0 solves those
7insecurities. This did result in a different crypto format, so it's not backward
8compatible. Use this program as a demonstration on how to re-encrypt your
9files/passwords/whatevers into the new format.
10'''
11
12import sys
13import rsa
14from 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.
20cleartext = 'Give me more cowbell'
21old_crypto = insecure.encrypt(cleartext, pub)
22print 'Old crypto:', old_crypto
23print
24
25# Decrypt and re-encrypt the contents to make it compatible with the new RSA
26# module.
27decrypted = insecure.decrypt(old_crypto, priv)
28new_crypto = rsa.encrypt(decrypted, pub)
29
30print 'New crypto:', new_crypto
31print
32