翻譯|使用教程|編輯:李顯亮|2020-02-26 11:19:50.030|閱讀 849 次
概述:數(shù)字簽名用于保護(hù)PDF文檔,然后再與第三方共享。對PDF文檔進(jìn)行數(shù)字簽名可以通過使用數(shù)字簽名驗(yàn)證文檔來檢測篡改。本文將展示如何在C#中對PDF文檔進(jìn)行數(shù)字簽名和驗(yàn)證。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
數(shù)字簽名用于保護(hù)PDF文檔,然后再與第三方共享。對PDF文檔進(jìn)行數(shù)字簽名可以通過使用數(shù)字簽名驗(yàn)證文檔來檢測篡改。
Aspose.PDF for .NET是一種PDF處理和解析API,用于在跨平臺應(yīng)用程序中執(zhí)行文檔管理和操作任務(wù),可以輕松用于生成,修改,轉(zhuǎn)換,渲染,保護(hù)和打印PDF文檔,而無需使用Adobe Acrobat。
為了使用數(shù)字簽名以編程方式保護(hù)PDF文檔,本文將展示如何在C#中對PDF文檔進(jìn)行數(shù)字簽名和驗(yàn)證。最終,將學(xué)習(xí)如何:
近日,.NET版Aspose.PDF升級到v20.2版,解決VerticalAlignment對TextBoxField不起作用的問題,修復(fù)PDF到HTML之間轉(zhuǎn)換等多項(xiàng)Bug,感興趣的朋友可點(diǎn)擊下方按鈕下載最新版。
點(diǎn)擊下載最新版Aspose.PDF for .NET
以下是使用Aspose.PDF for .NET簽署PDF文檔的步驟。
以下代碼示例顯示了如何在C#中向PDF文檔添加數(shù)字簽名。
// Load PDF document using (Document pdfDocument = new Document("Document.pdf")) { using (PdfFileSignature signature = new PdfFileSignature(pdfDocument)) { PKCS7 pkcs = new PKCS7("certificate.pfx", "1234567890"); // Use PKCS7/PKCS7Detached objects DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100); // Set signature appearance signature.SignatureAppearance = @"aspose-logo.png"; // Create any of the three signature types signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature); // Save digitally signed PDF file signature.Save("Digitally Signed PDF.pdf"); } }
使用TimestampSettings類提供詳細(xì)信息,從而使用TimeStamp服務(wù)器對PDF文檔進(jìn)行簽名。以下代碼示例演示如何使用C#中的TimeStamp服務(wù)器對PDF文檔進(jìn)行數(shù)字簽名。
// Load PDF document using (Document pdfDocument = new Document("Document.pdf")) { using (PdfFileSignature signature = new PdfFileSignature(pdfDocument)) { PKCS7 pkcs = new PKCS7("certificate.pfx", "WebSales"); // Use PKCS7/PKCS7Detached objects TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted pkcs.TimestampSettings = timestampSettings; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100); // Create any of the three signature types signature.Sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs); // Save output PDF file signature.Save("Output.pdf"); } }
使用以下步驟驗(yàn)證經(jīng)過數(shù)字簽名的PDF文檔:
下面的代碼示例演示如何使用C#驗(yàn)證PDF中的數(shù)字簽名。
// Load PDF document using (Document pdfDocument = new Document("Document.pdf")) { using (PdfFileSignature signature = new PdfFileSignature(pdfDocument)) { IListsigNames = signature.GetSignNames(); if (sigNames.Count > 0) // Any signatures? { if (signature.VerifySigned(sigNames[0] as string)) // Verify first one { if (signature.IsCertified) // Certified? { if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission { // Do something } } } } } }還想要更多嗎?您可以點(diǎn)擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn