Encrypt and decrypt files with pyAesCrypt
masterThe simplest way to use pyAesCrypt is via the encryptFile and decryptFile functions. These functions handle file I/O automatically. You can optionally provide a bufferSize (in bytes) to control memory usage during the process; the default is 64KB.
Security Note: pyAesCrypt is compatible with AES Crypt file format (version 2). Note that version 2 does not authenticate the "file size modulo 16" byte, meaning an attacker with write access to the encrypted file could potentially alter the plaintext file size by up to 15 bytes.
import pyAesCrypt
password = "please-use-a-long-and-random-password"
# encrypt
pyAesCrypt.encryptFile("data.txt", "data.txt.aes", password)
# decrypt
pyAesCrypt.decryptFile("data.txt.aes", "dataout.txt", password)