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.

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.results.FileInfo;
// ...

try (Viewer viewer = new Viewer("protected.pdf")) {
    FileInfo fileInfo = viewer.getFileInfo();

    System.out.println("File type is: " + fileInfo.getFileType());
    System.out.println("File encrypted: " + fileInfo.isEncrypted());
}
Tip
Download a sample application written in Java that uses this code snippet. You can run the application locally using the mvn exec:java command. Ensure you have the Java and Maven installed beforehand.

The following shows a sample console output:

$ mvn exec:java -q
File type is: Portable Document Format File (.pdf)
File encrypted: true

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