Check if a file is encrypted

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

The encryption protects data and allows only authorized people to open the file. So, only those who have an encryption key (such as a password) can open and view a file.

Check if a file is encrypted online

  1. Navigate to the GroupDocs.Viewer App.

GroupDocs.Viewer App

  1. Upload your file. If you are prompted to enter a password to open the file, it is encrypted.

GroupDocs.Viewer App password prompt

Warning
It’s important to be cautious about uploading sensitive files to online services. For critical files, we recommend using a programmatic method.

Programmatically check for file encryption

Use the GetFileInfo() method that returns the file type and flag that indicates if the file is encrypted. The following code snippet shows how to check if a file is encrypted.

using System;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Results;
// ...

using (Viewer viewer = new Viewer("protected.pdf"))
{
    // Get file information.
    var fileInfo = viewer.GetFileInfo();

    // Display the file type and flag if the file is encrypted.
    Console.WriteLine("File type is: " + fileInfo.FileType);
    Console.WriteLine("File encrypted: " + fileInfo.Encrypted);
}
Imports System
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Results
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("protected.pdf")
            ' Get file information.
            Dim fileInfo = viewer.GetFileInfo()
        
            ' Display the file type and flag if the file is encrypted.
            Console.WriteLine("File type is: " & fileInfo.FileType.ToString())
            Console.WriteLine("File encrypted: " & fileInfo.Encrypted.ToString())
        End Using
    End Sub
End Module

protected.pdf is the sample file used in this example. Click here to download it.

File type is: Portable Document Format File (.pdf)
File encrypted: True

Download full output

Tip
Download a sample application written in C# that uses this code snippet. You can run the application locally using the dotnet run command. Ensure you have the .NET SDK installed beforehand.

The following image shows a sample console output:

To learn how to open an encrypted file, please refer to Load password-protected document documentation topic.