PyCrypto and RSA
Gandalf
gandalf at geochemsource.com
Sat Feb 28 10:06:18 EST 2004
Hello!
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
Generator).
Well, this was not actually an anwer to your question. I did not want to
offend you. It was only a suggestion.
Cheers,
G
Carmine Noviello wrote:
>Hi,
>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], "")
> bits.append(cipheredText[0])
> pos += chunklen
>
>file.writelines(bits)
>
>This code seemingly works. I have problems with the code that decrypts the
>ciphered text.
>
>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
mailing list