msoffcrypto package#

Subpackages#

Module contents#

msoffcrypto.OfficeFile(file)[source]#

Return an office file object based on the format of given file.

Parameters:

file (_io.BufferedReader) – Input file.

Returns:

BaseOfficeFile object.

Examples

>>> with open("tests/inputs/example_password.docx", "rb") as f:
...     officefile = OfficeFile(f)
...     officefile.keyTypes
('password', 'private_key', 'secret_key')
>>> with open("tests/inputs/example_password.docx", "rb") as f:
...     officefile = OfficeFile(f)
...     officefile.load_key(password="Password1234_", verify_password=True)
>>> with open("README.md", "rb") as f:
...     officefile = OfficeFile(f)
Traceback (most recent call last):
    ...
msoffcrypto.exceptions.FileFormatError: ...
>>> with open("tests/inputs/example_password.docx", "rb") as f:
...     officefile = OfficeFile(f)
...     officefile.load_key(password="0000", verify_password=True)
Traceback (most recent call last):
    ...
msoffcrypto.exceptions.InvalidKeyError: ...

Given file handle will not be closed, the file position will most certainly change.