翻譯|使用教程|編輯:李顯亮|2020-07-20 10:56:00.320|閱讀 676 次
概述:為了以編程方式對(duì)PDF文檔進(jìn)行數(shù)字簽名,在本文中,將展示如何使用Java在PDF中添加和驗(yàn)證數(shù)字簽名。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
PDF中的數(shù)字簽名使您可以在與利益相關(guān)者共享文檔之前保護(hù)其安全。可以輕松地檢測和驗(yàn)證數(shù)字簽名的PDF文檔內(nèi)容的偽造。
為了以編程方式對(duì)PDF文檔進(jìn)行數(shù)字簽名,在本文中,將展示如何使用Java在PDF中添加和驗(yàn)證數(shù)字簽名。以下是我們將在此處探討的一些方案:
>>如果想要測試這項(xiàng)新功能,可點(diǎn)擊這里下載最新版試用。
以下是使用Aspose.PDF for Java將數(shù)字簽名添加到PDF文檔的步驟。
以下代碼示例顯示了如何使用Java對(duì)PDF進(jìn)行數(shù)字簽名。
// Create a Document object Document doc = new Document("input.pdf"); PdfFileSignature signature = new PdfFileSignature(doc); PKCS7 pkcs = new PKCS7("certificate.pfx", "1234567890"); // Use PKCS7/PKCS7Detached objects DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms); Rectangle rect = new Rectangle(100, 600, 400, 100); // Set signature appearance signature.setSignatureAppearance("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");
Aspose.PDF for Java還允許您使用TimeStamp服務(wù)器將數(shù)字簽名添加到PDF。該 TimestampSettings 類是用于這一目的。以下代碼示例顯示了如何使用Java使用TimeStamp服務(wù)器將數(shù)字簽名添加到PDF。
// Create a Document object Document doc = new Document("input.pdf"); PdfFileSignature signature = new PdfFileSignature(doc); PKCS7 pkcs = new PKCS7("certificate.pfx", "1234567890"); // Use PKCS7/PKCS7Detached objects TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted pkcs.setTimestampSettings(timestampSettings); Rectangle rect = new Rectangle(100, 600, 400, 100); // Set signature appearance signature.setSignatureAppearance("aspose-logo.png"); // Create any of the three signature types signature.sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs); // Save digitally signed PDF file signature.save("Digitally Signed PDF.pdf");
收到經(jīng)過數(shù)字簽名的PDF時(shí),您可以非常輕松地驗(yàn)證其簽名。以下是驗(yàn)證經(jīng)過數(shù)字簽名的PDF的步驟。
下面的代碼示例演示如何使用Java驗(yàn)證經(jīng)過數(shù)字簽名的PDF文檔。
// Create PDF File Signature PdfFileSignature pdfSign = new PdfFileSignature(); // Bind PDF pdfSign.bindPdf("Digitally Signed PDF.pdf"); // Verify signature using signature name if (pdfSign.verifySigned("Signature1")) { if (pdfSign.isCertified()) // Certified? { if (pdfSign.getAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission { // Do something } } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn