Page MenuHomePhabricator

Public | Add Field for Password-Protected Status
Open, WishlistPublic

Description

Kathryn [[ https://helpdesk.karenware.com/scp/tickets.php?id=701 | suggested need for being able to check password-protected status ]]for PDF, Word, and Excel files.

As a compliance check, all sensitive data files need to be password protected, whether they are PDFs, Excel, or Word files. I need a software that can show me if we missed any files that need to be encrypted/protected, for compliance purposes. I’d love the ability to see both protected AND un-protected files. Most software I’ve come across will only show that protected files in a list format.

Perhaps this could be added for a later version.

https://docs.microsoft.com/en-us/uwp/api/windows.data.pdf.pdfdocument
IsPasswordProtected Gets whether the Portable Document Format (PDF) document is password-protected.

Word and Excel might require interop with the applications installed on the machine:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word
https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel

Here is a method by examining the file directly from https://stackoverflow.com/questions/14347513/how-to-detect-if-a-word-document-is-password-protected-before-uploading-the-file/14347730#14347730:

public static Boolean IsProtected(String file)
{
    Byte[] bytes = File.ReadAllBytes(file);

    String prefix = Encoding.Default.GetString(bytes.Take(2).ToArray());

    // Zip and not password protected.
    if (prefix == "PK")
        return false;

    // Office format.
    if (prefix == "ÐÏ")
    {
        // XLS 2003
        if (bytes.Skip(0x208).Take(1).ToArray()[0] == 0xFE)
            return true;

        // XLS 2005
        if (bytes.Skip(0x214).Take(1).ToArray()[0] == 0x2F)
            return true;

        // DOC 2005
        if (bytes.Skip(0x20B).Take(1).ToArray()[0] == 0x13)
            return true;

        // Guessing
        if (bytes.Length < 2000)
            return false;

        // DOC/XLS 2007+
        String start = Encoding.Default.GetString(bytes.Take(2000).ToArray()).Replace("\0", " ");

        if (start.Contains("E n c r y p t e d P a c k a g e"))
            return true;

        return false;
    }

    // Unknown format.
    return false;
}

Event Timeline

Joe created this task.Jun 14 2019, 11:00 AM
Joe created this object in space S5 Public.
Joe triaged this task as Wishlist priority.
Joe created this object with visibility "Public (No Login Required)".
Joe updated the task description. (Show Details)
Joe updated the task description. (Show Details)Jun 14 2019, 11:23 AM