I am trying to encrypt and decrypt files RSA library. I’m always successful with the encryption but i get an overflow error during the decryption I get an exception saying “OverflowError: 64 bytes needed for message, but there is only space for 53” here is the code below;
import rsa
pubkey,privekey= rsa.newkeys(512)
path = "C:\Users\PC\Documents\Document.rtf"
with open (path,'rb') as thefile:
contents = thefile.read()
contents_encryp = rsa.encrypt(contents,pubkey)
with open(path, 'wb') as thefile:
thefile.write(contents_encryp)
here is the decryption code below;
import rsa
from encryptor import contents_encryp,privekey
path = "C:\Users\PC\Documents\Document.rtf"
with open (path,'rb') as thefile:
contents = thefile.read()
contents_decryp = rsa.decrypt(contents_encryp,privekey)
with open(path, 'wb') as thefile:
thefile.write(contents_decryp)
New contributor
NDK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3