Check if a file is encrypted

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.
    FileInfo 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 As 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
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.