- 使用密码保护PowerPoint PPTX
- 使用数字签名保护PowerPoint文件
- 验证经过数字签名的PowerPoint演示文稿
为了保护PowerPoint文件,将使用Aspose.Slides。它是一个功能强大且功能丰富的API,可用于创建,操作和转换PowerPoint文件。此外,它使您可以使用密码或数字签名保护PowerPoint PPTX / PPT演示文稿。
>>你可以点击这里下载Aspose.Slides for java最新版测试体验。
整合所有格式API处理控件Aspose.Total永久授权火热促销中,联系客服立马1分钟了解全部!
使用Java使用密码保护PowerPoint PPTX
以下是使用Aspose.Slides for Java用密码保护PowerPoint PPTX文件的步骤。
- 首先,使用Presentation 类加载PPTX演示 文稿。
- 使用Presentation.getProtectionManager()。encrypt(String) 方法使用密码对 演示文稿进行加密。
- 最后,使用Presentation.save(String,SaveFormat) 方法创建 演示文稿。
下面的代码示例演示如何使用Java保护PowerPoint PPTX文件。
// Instantiate a Presentation object that represents a presentation filePresentation presentation = new Presentation("presentation.pptx");// Protect PPTX with passwordpresentation.getProtectionManager().encrypt("password");// Save the PPTXpresentation.save("protected-presentation.pptx", SaveFormat.Pptx);
使用Java使用数字签名保护PowerPoint文件
还可以对PowerPoint PPTX演示文稿进行数字签名,以确保其内容的真实性。以下是将数字签名添加到PPTX文件的步骤。
- 使用Presentation 类加载PPTX演示 文稿。
- 使用DigitalSignature类创建一个新的数字签名。
- 使用DigitalSignature.setComments(String)方法添加用于签名的注释。
- 使用Presentation.getDigitalSignatures()。add(DigitalSignature)方法对PowerPoint演示文稿进行数字签名。
- 使用Presentation.save(String,SaveFormat) 方法保存更新的演示 文稿。
下面的代码示例演示如何使用Java对PowerPoint演示文稿进行数字签名。
// Instantiate a Presentation object that represents a presentation filePresentation presentation = new Presentation("presentation.pptx");// Create DigitalSignature object with PFX file and PFX passwordDigitalSignature signature = new DigitalSignature("testsignature1.pfx", "testpass1");// Comment new digital signaturesignature.setComments("Aspose.Slides digital signing test.");// Add digital signature to presentationpresentation.getDigitalSignatures().add(signature);// Save the PPTXpresentation.save("protected-presentation.pptx", SaveFormat.Pptx);
验证Java中经过数字签名的PowerPoint演示文稿
除了添加数字签名之外,您还可以验证PowerPoint演示文稿中的现有签名。以下是验证PPTX文件中的数字签名的步骤。
- 使用Presentation 类加载PPTX演示 文稿。
- 遍历Presentation.getDigitalSignatures()方法返回的集合中的每个IDigitalSignature。
- 使用IDigitalSignature.isValid()方法检查签名的有效性。
下面的代码示例演示如何使用Java验证PowerPoint PPTX文件中的数字签名。
// Instantiate a Presentation object that represents a presentation filePresentation presentation = new Presentation("presentation.pptx");// Check if digital signatures are availableif (presentation.getDigitalSignatures().size() > 0) {boolean allSignaturesAreValid = true; // Loop through digital signaturesfor (IDigitalSignature signature : presentation.getDigitalSignatures()) {System.out.println(signature.getSignTime().toString() + " -- " + (signature.isValid() "VALID" : "INVALID"));allSignaturesAreValid &= signature.isValid();}if (allSignaturesAreValid)System.out.println("Presentation is genuine, all signatures are valid.");elseSystem.out.println("Presentation has been modified since signing.");}// Save the PPTXpresentation.save("protected-presentation.pptx", SaveFormat.Pptx);
如果你想试用Aspose的全部完整功能,可 联系在线客服获取30天临时授权体验。
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!