PyCrypto and RSA
gandalf at geochemsource.com
Sat Feb 28 16:06:18 CET 2004
I think you should not do this. RSA encryption is quite expensive (in
terms of processor time). You should only encrypt
a session key with RSA and then use that session key with a symmetric
algorigthm (e.g. Blowfish, AES, TwoFish etc)
to encode a large file. You can create a session key from a
cryptographically secure PRNG (Pseudo Random Number
Well, this was not actually an anwer to your question. I did not want to
offend you. It was only a suggestion.
Carmine Noviello wrote:
>I want to say first of all that I'm totally a newbie in cryptography world.
>Is there someone can show me a simple example on how to use PyCrypto lib and
>RSA to encrypt large text file? I'm trying to do it in this way.
>First of all I split the text file in sub parts each one of key.size() // 8
>size. Then I encrypt using RSA PublicKey algorithm and store each line in a
>target file. This is the pseudo-code:
>size = len(plaintext)
>bits = 
>pos = 0
>chunklen = key.size() // 8
>while pos < size:
> cipheredText = key.encrypt(plaintext[pos:pos+chuncklen], "")
> pos += chunklen
>This code seemingly works. I have problems with the code that decrypts the
>blocksize = (privkey.size() // 8) + 1
>plaintext = ""
>line = fo.read(blocksize)
>while line != "":
> plaintext += privkey.decrypt(line)
> line = file.read(blocksize)
>Often, but not every time, this code raise an exception "Ciphertext too
>large". I can't understand where I went wrong.
>Thanks in advance.
More information about the Python-list