Giri Giri - 26 days ago 12
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?

Thanks..

string passprotectedfile = filename;

using (Stream input = new FileStream(signedfile, FileMode.Open, FileAccess.Read,
FileShare.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(), "",
PdfWriter.ALLOW_SCREENREADERS);
}
}

Answer

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.