### Encrypt File using Command-Line Script Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Encrypts a file using the pyAesCrypt command-line script. The output file is automatically named with a .aes extension. ```bash pyAesCrypt -e test.txt ``` -------------------------------- ### Encrypt File to Specific Output using Command-Line Script Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Encrypts a file using the pyAesCrypt command-line script and specifies a custom output file name. ```bash pyAesCrypt -e test.txt -o test2.txt.aes ``` -------------------------------- ### Encrypt and Decrypt File Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Basic file encryption and decryption using default buffer size. This is the recommended method for file operations. ```python 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) ``` -------------------------------- ### Encrypt and Decrypt File with Custom Buffer Size Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst File encryption and decryption with a specified buffer size. Useful for optimizing performance with large files. ```python import pyAesCrypt # custom encryption/decryption buffer size (default is 64KB) bufferSize = 128 * 1024 password = "please-use-a-long-and-random-password" # encrypt pyAesCrypt.encryptFile("data.txt", "data.txt.aes", password, bufferSize) # decrypt pyAesCrypt.decryptFile("data.txt.aes", "dataout.txt", password, bufferSize) ``` -------------------------------- ### Decrypt File to Specific Output using Command-Line Script Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Decrypts a file using the pyAesCrypt command-line script and specifies a custom output file name. ```bash pyAesCrypt -d test.txt.aes -o test2.txt ``` -------------------------------- ### Decrypt File using Command-Line Script Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Decrypts a file using the pyAesCrypt command-line script. The output file is automatically named by removing the .aes extension. ```bash pyAesCrypt -d test.txt.aes ``` -------------------------------- ### Encrypt and Decrypt Binary Streams Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Encryption and decryption of binary data using streams. Requires specifying a buffer size. ```python import pyAesCrypt from os import stat, remove # encryption/decryption buffer size - 64K # with stream-oriented functions, setting buffer size is mandatory bufferSize = 64 * 1024 password = "please-use-a-long-and-random-password" # encrypt with open("data.txt", "rb") as fIn: with open("data.txt.aes", "wb") as fOut: pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize) # decrypt with open("data.txt.aes", "rb") as fIn: try: with open("dataout.txt", "wb") as fOut: # decrypt file stream pyAesCrypt.decryptStream(fIn, fOut, password, bufferSize) except ValueError: # remove output file on error remove("dataout.txt") ``` -------------------------------- ### In-Memory Encryption and Decryption Source: https://github.com/marcobellaccini/pyaescrypt/blob/master/README.rst Encrypts and decrypts binary data directly in memory using BytesIO streams. Requires specifying a buffer size. ```python import pyAesCrypt import io bufferSize = 64 * 1024 password = "please-use-a-long-and-random-password" # binary data to be encrypted pbdata = b"This is binary plaintext \x00\x01" # input plaintext binary stream fIn = io.BytesIO(pbdata) # initialize ciphertext binary stream fCiph = io.BytesIO() # initialize decrypted binary stream fDec = io.BytesIO() # encrypt stream pyAesCrypt.encryptStream(fIn, fCiph, password, bufferSize) # print encrypted data print("This is the ciphertext:\n" + str(fCiph.getvalue())) # go back to the start of the ciphertext stream fCiph.seek(0) # decrypt stream pyAesCrypt.decryptStream(fCiph, fDec, password, bufferSize) # print decrypted data print("Decrypted data:\n" + str(fDec.getvalue())) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.