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.

If you want to check if a file is encrypted, 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. Also, you can find this example on GitHub.

using (Viewer viewer = new Viewer("encrypted.pdf"))
{
	// Get file information.
    Results.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);
}

The following image shows a sample console output:

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