Recursive AI

Check an Office file for missing EncryptionInfo in C#

OneDocument is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

A .docx or .xlsx encrypted with ECMA-376 uses a compound file instead of a ZIP: it’s a container of named streams that holds /EncryptionInfo and /EncryptedPackage.

Terminal
dotnet add package RecursiveAI.OneDocument

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneDocument.Cfb;
 
var path = args.FirstOrDefault()
    ?? "missing-info.cfb";
using var file = CfbPackage.Open(path);
var info = file.FindPart("/EncryptionInfo");
var payload = file.FindPart("/EncryptedPackage");
Console.WriteLine(info is null
    ? "/EncryptionInfo: missing"
    : "/EncryptionInfo: present");
Console.WriteLine(payload is null
    ? "/EncryptedPackage: missing"
    : "/EncryptedPackage: present");

Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.

The zip includes missing-info.cfb, a synthetic compound file with just one stream: /EncryptedPackage, containing the placeholder bytes 01 02 03 in hex, not real ciphertext. Run from the folder containing the sample. The program prints:

Text
/EncryptionInfo: missing
/EncryptedPackage: present

To check your own file, pass its path after dotnet run --. If the file isn’t a compound file or is too damaged to open, CfbPackage.Open throws an OfficeException instead of reporting a missing stream.

Variations

List every stream path

Add this after the two lookups to see what the directory contains, including streams in nested storages:

C#
foreach (var part in file.Parts)
    Console.WriteLine(part.Name);

With missing-info.cfb, this adds one line:

Text
/EncryptedPackage

The short answer

If you see “ECMA-376 encrypted file missing /EncryptionInfo,” open the file as a compound container and check for /EncryptionInfo and /EncryptedPackage at the root. If /EncryptedPackage is present but /EncryptionInfo is missing, you’ve confirmed the directory contains an entry for the payload but no entry for the descriptor. The check doesn’t read either stream’s contents, take a password, or attempt recovery.

What does “ECMA-376 encrypted file missing /EncryptionInfo” mean?

An ordinary .xlsx, .docx, or .pptx is a ZIP package. With ECMA-376 document encryption, the encrypted package is stored inside a compound file: a container with a directory of named streams and storages, like files and folders inside the document. Microsoft’s Office Document Cryptography Structure, §2.3.4 describes the wrapper. The /EncryptedPackage stream holds the encrypted package; /EncryptionInfo describes the encryption. The descriptor has a different structure for Standard and Agile encryption.

The leading slash in CfbPackage.FindPart means “at the root.” A similarly named stream under another storage doesn’t satisfy the lookup. OneDocument looks for an exact name first and then ignores case, so /encryptioninfo at the root counts as present. Neither lookup checks the bytes: an empty or malformed descriptor can still have a directory entry.

What should I do with each result?

Use the output to separate a missing stream from a different problem:

  • Only /EncryptedPackage is present. The expected descriptor isn’t listed. That’s a structural finding, not evidence that the password is wrong or that the file can be decrypted. Check a fresh copy from the sender or source system.
  • Both streams are present. A missing root descriptor doesn’t explain the failure on this copy. The check says nothing about whether the descriptor or payload is readable or whether the encryption scheme is supported. With a supported, password-protected file, the normal Office reader can distinguish a required or incorrect password from a malformed header; the directory check doesn’t make those distinctions. See OneDocument’s encryption notes.
  • /EncryptedPackage is missing. You haven’t found the expected ECMA-376 payload, even if /EncryptionInfo exists. If neither is present, the file may be a different kind of compound document, such as a legacy .xls, for which these two entries aren’t the test for encryption.
  • The compound file won’t open. Don’t interpret that as either stream being missing. An ordinary, unencrypted XLSX is ZIP-based and should go through the workbook reader instead of this check. An unreadable compound container also can’t give you a directory result.
All onedocument recipes