数字签名验证电子文档的真实性和完整性,就像签名或印章(手工制作)一样。但是,数字签名比手写签名安全得多。

读完本文后,您将了解如何使用 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 功能 的更多信息,请参阅我们的文档.如果您有任何问题,可以在我们的论坛 上发帖。