Encrypt large file with Asymmetric cryptography

1.5k Views Asked by At

i want to encrypt a file with public key in python, Asymmetric methode im really use cryptography biblio and PyCrypto but all algorithm encrypt short text not big file i need solution for my problem , in cryptography biblio i use hazmat module . i converted my file to string format , so this is result :

'Data too long for key size. Encrypt less data or use a ValueError: Data too long for key size. Encrypt less data or use a larger key size.'

def Encrypt(file,public_key):
    encrypted = public_key.encrypt(
        file,
        padding.OAEP(
            mgf=padding.MGF1(algorithm=hashes.SHA256()),
            algorithm=hashes.SHA256(),
            label=None
        )
    )
    f = open('myEncreptedFile.txt', 'wb')
    f.write(encrypted)
    f.close()
0

There are 0 best solutions below