我使用c#創建和簽署pdf,itextsharp.Now我使用這個密碼保護和數字標記的代碼。首先我用password.Than我簽署保護。如何使用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);
那麼你面臨的問題是什麼? – Raghuveer
傳送的pdf是不是要求輸入密碼才能打開pdf? – Giri