{"id":1846,"library":"msoffcrypto-tool","title":"MS Office Crypto Tool","description":"msoffcrypto-tool is a Python library and command-line tool for decrypting and encrypting MS Office files (e.g., .doc, .xls, .ppt, .docx, .xlsx, .pptx) that are protected with a password or other keys. The current version is 6.0.0, released in February 2024. Releases are infrequent but active, addressing security updates and Python version compatibility.","status":"active","version":"6.0.0","language":"en","source_language":"en","source_url":"https://github.com/nolze/msoffcrypto-tool","tags":["office","encryption","decryption","security","excel","word","powerpoint"],"install":[{"cmd":"pip install msoffcrypto-tool","lang":"bash","label":"Install core library"},{"cmd":"pip install msoffcrypto-tool[all]","lang":"bash","label":"Install with all optional dependencies"}],"dependencies":[{"reason":"Core cryptographic operations.","package":"cryptography"},{"reason":"Parsing OLE compound file format.","package":"olefile"},{"reason":"Required for MSOFBA / VBA decryption.","package":"lief","optional":true},{"reason":"Required for scrypt-based key encryption.","package":"pylibscrypt","optional":true}],"imports":[{"symbol":"OfficeFile","correct":"from msoffcrypto import OfficeFile"},{"note":"Common exceptions like InvalidKeyError, FileFormatError are available under exceptions.","symbol":"exceptions","correct":"from msoffcrypto import exceptions"}],"quickstart":{"code":"import io\nimport os\nfrom msoffcrypto import OfficeFile, exceptions\n\n# --- IMPORTANT ---\n# This example demonstrates the API usage. The `encrypted_content` below is\n# NOT a real encrypted MS Office file and will not successfully decrypt.\n# For actual decryption, replace it with content read from a real encrypted file.\n\n# A minimal OLE header (not a full encrypted file) for API demonstration.\n# A real encrypted file starts with this and contains specific crypto structures.\nencrypted_content = b\"\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\" \\\n                    + b\"\\x00\" * 4000 # Placeholder for file content\n\n# Simulate reading an encrypted file\nencrypted_file_stream = io.BytesIO(encrypted_content)\n# Simulate an output file for decrypted content\ndecrypted_file_stream = io.BytesIO()\n\n# Get password from environment variable or set a default placeholder\npassword = os.environ.get('MSOFFCRYPTO_PASSWORD', 'YourStrongPassword') \n\ntry:\n    # Initialize OfficeFile with the encrypted stream\n    office_file = OfficeFile(encrypted_file_stream)\n\n    # Load the decryption key using the password\n    office_file.load_key(password=password)\n\n    # Decrypt the file to the output stream\n    office_file.decrypt(decrypted_file_stream)\n\n    print(\"API usage demonstrated successfully. Output stream has data.\")\n    # In a real scenario, decrypted_file_stream.getvalue() would contain the decrypted file content.\n\nexcept exceptions.InvalidKeyError:\n    print(\"Decryption failed: Invalid password.\")\nexcept exceptions.FileFormatError as e:\n    print(f\"Decryption failed: Invalid file format. {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n\n# Reset stream position if you want to read it again\nencrypted_file_stream.seek(0)\ndecrypted_file_stream.seek(0)","lang":"python","description":"This quickstart demonstrates the core API for decrypting an MS Office file. It uses an in-memory byte stream to simulate file I/O. Remember to replace the `encrypted_content` with actual data from a real encrypted file for functional decryption. It also shows handling common decryption exceptions."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer, or pin msoffcrypto-tool to a version < 6.0.0 if legacy Python is unavoidable (e.g., `pip install msoffcrypto-tool<6.0`).","message":"Version 6.0.0 dropped support for Python 3.7 and 3.8. The library now requires Python >= 3.10.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Install the library with the `[all]` extra to include all optional dependencies: `pip install msoffcrypto-tool[all]`.","message":"Specific decryption features, such as MSOFBA/VBA decryption or files encrypted with scrypt-based keys, require optional dependencies ('lief' and 'pylibscrypt' respectively). Without them, decryption of these specific components might fail or be incomplete.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always test with your specific file types. Refer to the GitHub repository's issue tracker or documentation for details on supported formats and limitations.","message":"Not all MS Office file types or encryption methods are universally supported. While it handles common OLE-based (.doc, .xls, .ppt) and some OOXML formats (.docx, .xlsx, .pptx) with standard password protection, very old binary formats or newer, less common encryption schemes might not work.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}