Search code examples
pythonencryptionpgp

How to decrypt large files in chunks?


I am trying to decrypt a large file with PgPy and had this problem:

OverflowError: integer 2632261350 does not fit '32-bit int'

Clearly the size of the file is not suitable, so I would like to know how I can decrypt large files in chunks? we can decrypt blocks of data? or we can only decrypt the whole data with the key that we have?


Solution

  • Not sure about pgpy but have a lookt at python-gnupg. It is a wrapper for gnupg that is able to encrypt/decrypt files as a stream.

    with stream as open(filename,"rb"):
        decrypted_data = gpg.decrypt_file(stream) # e.g. after stream = open(filename, "rb")
    

    I believe it is more a memory issue than a library issue. If you can decrypt as a stream with pgpy, you would obtain the same result.