Problem:If you are using iTestShap in Dot net application and generating PDF with owner passward. After that you are trying to open that password protected in again in Dot net code then you may face the error or exception of itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password.
Solution:This is because you are not supplying the password while you opening that pdf file in itextsharp using PdfReader.
Creating Pdf file using owner password:PdfWriter docWriter = PdfWriter.GetInstance(doc, new FileStream(pdfFileName, FileMode.Create));
byte OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
docWriter.SetEncryption(null, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
Now you are trying to open that file:PdfReader pdfReader = new PdfReader(pdfFileName);
Correct code:byte OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
PdfReader pdfReader = new PdfReader(pdfFileName, OWNER);
So conclusion is that be sure you are supplying the password while opening the password protected file in PdfReader in C# or VB.net code: