數字簽名驗證電子文檔的真實性和完整性,就像簽名或印章(手工製作)一樣。但是,數字簽名比手寫簽名安全得多。

讀完本文後,您將了解如何使用 Java 向 PowerPoint 演示文稿添加數字簽名。

用於向 PowerPoint PPT 添加數字簽名的 Java API

如果您希望使用幾行 Java 代碼向 PPT 演示文稿添加數字簽名,那麼您需要:

  • 用於 Java 的 Aspose.Slides, a powerful PowerPoint library used to create, edit, and manipulate PPT and PPTX presentations. For instructions on installing Aspose.Slides, see this Installation guide.
  • 簽名證書:在創建數字簽名之前,您首先需要一個簽名證書。此類證書通常由已知的證書頒發機構 (CA) 頒發,但您也可以創建自己的證書。

數字簽名必須滿足以下條件:使用有效簽名,與之關聯的證書必須是最新的(未過期),並且(理想情況下)它應該來自信譽良好或知名的證書頒發機構,並且簽名者或簽名組織必須被信任。

給PPT添加數字簽名的Java代碼

有了您的數字證書並在您的系統上安裝了 Aspose.Slides,您必須按照以下說明將數字簽名添加到 Java 中的 PowerPoint 演示文稿:

  1. 使用 Presentation 類,加載相關的 PowerPoint 文件。
  2. 創建一個數字簽名對象,然後將數字簽名PFX文件和密碼傳遞給它。
  3. 添加數字簽名。
  4. 保存更改的演示文稿。

此 Java 代碼向您展示瞭如何向 PowerPoint 添加數字簽名:

// 打開演示文稿文件
Presentation pres = new Presentation();
try {
    // 使用 PFX 文件和 PFX 密碼創建 DigitalSignature 對象 
    DigitalSignature signature = new DigitalSignature("testsignature1.pfx", "testpass1");

    // 評論新數字簽名
    signature.setComments("Aspose.Slides digital signing test.");

    // 向演示文稿添加數字簽名
    pres.getDigitalSignatures().add(signature);

    // 保存演示文稿
    pres.save("SomePresentationSigned.pptx", SaveFormat.Pptx);
} finally {
    pres.dispose();
}

驗證數字簽名的 PowerPoint PPT

如果您收到帶有數字簽名的 PowerPoint,則運行驗證操作以檢查並確認您手中的文件在簽名後未被修改。此過程本質上是對 PPT 或 PPTX 演示文稿的真實性和完整性的測試。

按照以下說明驗證已使用數字簽名簽名的 PowerPoint:

  1. 使用 Presentation 類,加載相關的 PowerPoint 文件。
  2. 檢查 PowerPoint 是否已簽名。
  3. 檢查簽名(用於簽署演示文稿)是否有效。

運行此 Java 代碼以驗證數字簽名的 PowerPoint 文檔:

// 打開演示文稿
Presentation pres = new Presentation("SomePresentationSigned.pptx");
try {
    if (pres.getDigitalSignatures().size() > 0)
    {
        boolean allSignaturesAreValid = true;

        System.out.println("Signatures used to sign the presentation: ");

        // 檢查所有數字簽名是否有效
       for (IDigitalSignature signature : pres.getDigitalSignatures())
        {
            System.out.println(signature.getComments() + ", "
                    + signature.getSignTime().toString() + " -- " + (signature.isValid() ? "VALID" : "INVALID"));
            allSignaturesAreValid &= signature.isValid();
        }

        if (allSignaturesAreValid)
            System.out.println("Presentation is genuine. All signatures are valid.");
        else
            System.out.println("Presentation has been modified since signing.");
    }
} finally {
    if (pres != null) pres.dispose();
}

獲得免費許可證

如果您想不受限制地嘗試 Aspose.Slides 的功能,我們建議您獲得一個免費的臨時許可證

結論

我們相信您現在知道如何使用 Java 將數字簽名添加到 PowerPoint 演示文稿中。其他以安全為主題的文章(例如關於 密碼保護 PowerPoint 演示文稿的文章)可能會派上用場。

要了解有關 Aspose.Slides 功能 的更多信息,請參閱我們的文檔.如果您有任何問題,可以在我們的論壇 上發帖。