{"id":8466,"library":"pyaescrypt","title":"pyAesCrypt","description":"pyAesCrypt is a Python library (version 6.1.1) for encrypting and decrypting files and streams using the AES Crypt format (version 2). It provides a straightforward API for secure file and stream operations with AES encryption, often seeing patch and minor releases and occasional major updates that introduce breaking changes or significant features.","status":"active","version":"6.1.1","language":"en","source_language":"en","source_url":"https://github.com/marcobellaccini/pyAesCrypt","tags":["encryption","aes","cryptography","files","streams"],"install":[{"cmd":"pip install pyaescrypt","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides the underlying cryptographic primitives for AES encryption/decryption.","package":"pycryptodome"}],"imports":[{"symbol":"pyAesCrypt","correct":"import pyAesCrypt"},{"symbol":"encryptFile","correct":"import pyAesCrypt\npyAesCrypt.encryptFile(...)"},{"symbol":"decryptFile","correct":"import pyAesCrypt\npyAesCrypt.decryptFile(...)"},{"symbol":"encryptStream","correct":"import pyAesCrypt\npyAesCrypt.encryptStream(...)"},{"symbol":"decryptStream","correct":"import pyAesCrypt\npyAesCrypt.decryptStream(...)"},{"symbol":"AESCryptException","correct":"from pyAesCrypt import AESCryptException"}],"quickstart":{"code":"import pyAesCrypt\nimport os\n\n# --- Setup (create dummy file) ---\ninput_file = \"data.txt\"\nencrypted_file = \"data.aes\"\ndecrypted_file = \"data.txt.out\"\npassword = os.environ.get('AESCRYPT_PASSWORD', 'mySuperSecretPassword123') # Replace with strong password\nbuffer_size = 64 * 1024 # 64KB\n\nwith open(input_file, 'w') as f:\n    f.write('This is a test message to be encrypted.')\n\nprint(f\"Original file '{input_file}' created.\")\n\n# --- Encryption ---\ntry:\n    pyAesCrypt.encryptFile(input_file, encrypted_file, password, buffer_size)\n    print(f\"File '{input_file}' encrypted to '{encrypted_file}'.\")\n\n    # --- Decryption ---\n    pyAesCrypt.decryptFile(encrypted_file, decrypted_file, password, buffer_size)\n    print(f\"File '{encrypted_file}' decrypted to '{decrypted_file}'.\")\n\n    with open(decrypted_file, 'r') as f:\n        content = f.read()\n        print(f\"Decrypted content: '{content}'\")\n\n    # Verify content\n    with open(input_file, 'r') as f_orig, open(decrypted_file, 'r') as f_dec:\n        if f_orig.read() == f_dec.read():\n            print(\"Decryption successful and content matches original.\")\n        else:\n            print(\"WARNING: Decrypted content does NOT match original!\")\n\nexcept pyAesCrypt.AESCryptException as e:\n    print(f\"An encryption/decryption error occurred: {e}\")\nexcept FileNotFoundError as e:\n    print(f\"File not found error: {e}\")\nexcept PermissionError as e:\n    print(f\"Permission error: {e}\")\nfinally:\n    # --- Cleanup ---\n    for f in [input_file, encrypted_file, decrypted_file]:\n        if os.path.exists(f):\n            os.remove(f)\n            print(f\"Cleaned up '{f}'.\")\n","lang":"python","description":"This quickstart demonstrates how to encrypt and decrypt a file using `pyAesCrypt.encryptFile` and `pyAesCrypt.decryptFile`. It creates a dummy text file, encrypts it, decrypts it, prints the decrypted content, and then cleans up the temporary files. Remember to use a strong password and manage it securely."},"warnings":[{"fix":"Review error handling code. Replace general `IOError` catches with `pyAesCrypt.AESCryptException` or more specific exception types documented for pyAesCrypt.","message":"Public API exceptions for I/O errors were changed in version 5.0.0. Code catching specific `IOError` types might need to be updated to catch `pyAesCrypt.AESCryptException` or more specific custom exceptions introduced by the library.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Ensure all passwords meet modern complexity standards (e.g., length, mixed characters). Explicitly set `bufferSize` if your application requires specific memory usage or performance characteristics.","message":"Version 6.0.0 introduced an updated password complexity check. Passwords considered weak in newer versions might have worked in older ones, potentially causing `ValueError: Password too weak` during encryption attempts. Additionally, a default buffer size was set, which might slightly alter performance for applications that previously relied on unspecified buffer sizes.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"For compatibility with old files, add `pyAesCrypt.AESCryptVersion = 0` before calling decryption functions. Example: `pyAesCrypt.AESCryptVersion = 0; pyAesCrypt.decryptFile(...)`","message":"By default, `pyAesCrypt` encrypts and decrypts files using the AES Crypt format version 2. If you need to decrypt files created with very old versions of `pyAesCrypt` (0.x.x series), you must explicitly set `pyAesCrypt.AESCryptVersion = 0` *before* attempting decryption, otherwise decryption will likely fail or yield corrupted data.","severity":"gotcha","affected_versions":"All versions (when decrypting old files)"},{"fix":"Upgrade `pyaescrypt` to version 6.1.1 or newer to benefit from the stream encryption fix: `pip install --upgrade pyaescrypt`.","message":"A bug in stream encryption was fixed in version 6.1.1. Users on older 6.x.x versions (e.g., 6.0.0, 6.1.0) might encounter issues with corrupted output when using `encryptStream` or `decryptStream` functions.","severity":"gotcha","affected_versions":"6.0.0, 6.1.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify the file path and name. Ensure the input file exists before calling `encryptFile` or `decryptFile`.","cause":"The input file specified for encryption or decryption does not exist at the given path.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'non_existent_file.txt'"},{"fix":"Double-check the password. Ensure you are using the correct file and that it hasn't been tampered with. If decrypting old files, consider setting `pyAesCrypt.AESCryptVersion = 0`.","cause":"The provided password does not match the one used during encryption, or the encrypted file is corrupted/not a valid pyAesCrypt file.","error":"pyAesCrypt.AESCryptException: BadSignatureException: Wrong password or file corrupted"},{"fix":"Ensure the directory where the output file is to be created exists and that the current user/process has write permissions to it. Change the output path to a writable location if necessary.","cause":"The Python process does not have write permissions to the specified output directory or file.","error":"PermissionError: [Errno 13] Permission denied: 'output.aes'"},{"fix":"Choose a stronger password. It should typically be longer, and include a mix of uppercase and lowercase letters, numbers, and special characters.","cause":"Starting from version 6.0.0, pyAesCrypt enforces stricter password complexity rules, and the provided password did not meet them.","error":"ValueError: Password too weak"}]}