C
Carmine Noviello
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
os+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.
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
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.