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.

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.