How to catch a password protected pdf?

Hi, I am trying to identify a password protected file. When we create a document object it throws an error for a password protected file. How can we beforehand identify if it is password protected ?!

@charu.sharma

Would you kindly share your sample PDF document for our reference as well? We will investigate this case and address it accordingly.

Get_Started_With_Smallpdf - Corrupted.pdf (50.7 KB)
sample-protected.pdf (7.3 KB)

Uploaded is the password protected file. I was able to find a solution for the password protected file.
We were able to identify the protected file using the isencrypted flag.

However, do we have any such flag for corrupted pdf files ?! I have attached both files.
Please guide.

@charu.sharma

Please try to use below code snippet in order to determine whether a PDF document is invalid:

using (var pdfFileInfo = new Facades.PdfFileInfo(@"Corrupted.pdf"))
{
    if (!pdfFileInfo.IsPdfFile)
        Console.WriteLine("The given PDF content is invalid or encrypted.");
}