Giri Giri - 1 year ago 112
ASP.NET (C#) Question

how to password protect the digitally signed pdf?

I m creating and signing pdf using c#,itextsharp.Now i m using this code for password protection.

Can someone tellme why is this happening?


string passprotectedfile = filename;

using (Stream input = new FileStream(signedfile, FileMode.Open, FileAccess.Read,
using (Stream output = new FileStream(passprotectedfile, FileMode.Create,
FileAccess.Write, FileShare.None))
PdfReader reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, regno.ToString(), "",

Answer Source

The whole point of a digital signature is to ensure that nobody has tampered with the contents of the file. By adding a password you are modifying it so the digital signature that was applied is no longer valid and this is what the error message is telling you. You will need to resign the PDF file after modifying it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download