Recursive AI

What does “CDFV2 Encrypted” mean?

“CDFV2 Encrypted” describes an encrypted file in a compound container. It doesn’t tell you whether the Office file inside is Word, Excel, or PowerPoint.

OneDocument is Recursive AI’s free, open-source (MIT or Apache-2.0) .NET library for Word, Excel, and PowerPoint files. NuGet · GitHub · Docs

Install · .NET 10
dotnet new console
dotnet add package RecursiveAI.OneDocument --version 1.0.0

The short answer

“CDFV2 Encrypted” can mean a password-protected Office document or another encrypted compound file; if it’s password-protected, you need the password to identify the format inside.

The Unix file command (file(1) in the manual) uses CDF for Compound Document File: a container with named streams, much like files within a folder. CDFV2 isn’t a filename extension, and it doesn’t name the encryption algorithm. A modern Office file can have its entire package encrypted inside this container, while older binary Office formats such as DOC and XLS can also use compound storage without being encrypted.

Download secret-basic.docx into the project folder. This first example identifies the wrapper without opening the contents.

Replace Program.cs and run dotnet run.

Program.cs
using RecursiveAI.OneDocument;
 
Console.WriteLine(Office.Detect("secret-basic.docx"));
Output
EncryptedPackage

Can the label tell you which Office format is inside?

No. For password-encrypted modern Office packages, the compound file holds an EncryptionInfo stream and an EncryptedPackage stream. The first describes how the package was encrypted; the second holds the encrypted package. The same arrangement can hold a Word document, an Excel workbook, or a PowerPoint presentation. See Microsoft’s Office encryption specification and OneDocument’s container detection.

For example, file 5.46 gives the same label to the pinned Word fixture and Excel fixture:

Outputfile(1)
secret-basic.docx: CDFV2 Encrypted
secret-basic.xlsx: CDFV2 Encrypted

If the name is missing or unreliable, identify the inner format after opening the file with its password. Renaming the outer file won’t change what’s inside.

Which encrypted Office files can OneDocument read?

  • Modern Office packages: Agile and Standard AES encryption for DOCX, XLSX, PPTX, and XLSB.
  • Older binary Office files: RC4 1.1 and RC4 CryptoAPI for XLS, DOC, and PPT; XOR obfuscation for XLS and DOC.

The 1.0.0 scheme list excludes certificate-only Agile, extensible encryption, and RC4 in an ECMA-376 package, among other cases. A correct password doesn’t make an unsupported scheme readable. Browser WebAssembly also lacks the AES and MD5 implementations this release needs for some schemes.

What happens when the password is missing or wrong?

Pass the known password in OpenContext.Password. With a supported file that requires a user password, OneDocument raises OfficeEncryptedException if the password is missing or incorrect; the defect code distinguishes the two cases (password handling).

The secret-basic.docx fixture uses Standard encryption and the public sample password secret. Replace Program.cs with the example below and run dotnet run. It checks the decrypted bytes in memory without writing an unencrypted copy.

Program.cs.NET 10
using RecursiveAI.OneDocument;
using RecursiveAI.OneDocument.Encryption;
using RecursiveAI.OneDocument.Formats;
using RecursiveAI.OneDocument.IO;
 
const string path = "secret-basic.docx";
Console.WriteLine($"Detected: {Office.Detect(path)}");
foreach (string? password in new string?[] { null, "wrong", "secret" })
{
    using var source = ByteSource.FromFile(path);
    try
    {
        byte[] package = PackageEncryption.DecryptCompoundFile(
            source, new OpenContext(password: password));
        Console.WriteLine($"Inner format: {FormatSniffer.Detect(package)}");
    }
    catch (OfficeEncryptedException ex)
    {
        Console.WriteLine(ex.Defect.Code);
    }
}
Output
Detected: EncryptedPackage
encryption.password-required
encryption.password-incorrect
Inner format: Docx

The first result identifies the outer Office wrapper. Only the last result identifies the document inside. For work with the opened document itself, see the OneDocument encryption guide for the document, workbook, and presentation APIs.