我正在使用 c#、itextsharp 创建和签名 pdf。现在我使用此代码进行密码保护和数字签名。首先我使用密码进行保护。然后我正在签名。
传输的pdf在打开时不询问密码?有人能告诉我为什么会这样吗?
谢谢..
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);
}
}
我用于数字签名的代码。
PdfReader reader = new PdfReader(filename,pass);
Stream output = new FileStream(signedfile, FileMode.Create, FileAccess.Write, FileShare.None);
PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0');
Rectangle rect = new Rectangle(455, 105, 555, 170);
PdfSignatureAppearance appearance = stamper.SignatureAppearance;
appearance.SetVisibleSignature(rect, 1, "sign");
PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adobe.pkcs7.detached"));
PrivateKeySignature pks = new PrivateKeySignature(pk, "SHA-256");
MakeSignature.SignDetached(appearance, pks, chain, null, null, null, 0, true);
return filename;
然后我正在传输。
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=tes2.pdf");
Response.TransmitFile(signedfile);
Response.Flush();
File.Delete(signedfile);
File.Delete(newfile);
File.Delete(passprotectedfile);