Starting with PyCrypto 2.5, you can export the RSA private key and protect it with a passphrase. The DES triple key is internally derived from a passphrase and is used for actual encryption.
For example:
from Crypto import RSA from Crypto import Random random_generator = Random.new().read key = RSA.generate(1024, random_generator) exportedKey = key.exportKey('PEM', 'my secret', pkcs=1)
The variable exportedKey contains the ASCII version (PEM) of the key encoded in accordance with PKCS # 1 (cryptographic standard. Another option is pkcs=8 for - guess what is PKCS # 8). Since the result is standard, you can use it with several other programs, including openssl. And of course, you can import it back into python again via PyCrypto!
The exportKey method exportKey documented here .
SquareRootOfTwentyThree
source share