Python overflowError when trying to encrypt with RSA

Viewed 29

Im coding an encrypting/decrypting Programm, but when i try to encrypt more than like 50 characters i get an error

My code:

import rsa
import sys

#Die zu verschlüsselnte datei wird eingelessen
datei = open(sys.argv[1], "r+")
dateiinhalt = datei.read()

#Public key wird eingelessen
public = open("public.txt")
publickey = rsa.PublicKey.load_pkcs1(public.read())
public.close()

#Datei wird verschlüsselt
inhalt = rsa.encrypt(dateiinhalt.encode(), publickey)



#Änderungen werden wirksam gemacht
datei.truncate(0)
datei.close()
wichtig = open(sys.argv[1], "wb")
wichtig.write(inhalt)

print("Erfolgreich verschlüsselt")

Here the error:

Traceback (most recent call last):
  File "C:\Users\tom\Desktop\test_backup\verschlüsslung.py", line 16, in <module>
    inhalt = rsa.encrypt(dateiinhalt.encode(), publickey)
  File "C:\Users\tom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\rsa\pkcs1.py", line 195, in encrypt
    padded = _pad_for_encryption(message, keylength)
  File "C:\Users\tom\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\rsa\pkcs1.py", line 113, in _pad_for_encryption
    raise OverflowError(
OverflowError: 125 bytes needed for message, but there is only space for 117
0 Answers
Related