2种方法教你在C#中使用Aspose保护PPT文档

本文明确针对MS PowerPoint演示文稿的安全性,并提供保护PPTX文档安全的不同方法。在本文中,将学习如何使用C#使用密码或数字签名保护PowerPoint PPTX。

数字信息的保护一直是网络世界中的重要方面。为了保护数字内容,已经设计了各种方式和技术。因此,本文明确针对MS PowerPoint演示文稿的安全性,并提供保护PPTX文档安全的不同方法。在本文中,将学习如何使用C#使用密码或数字签名保护PowerPoint PPTX。

  • 使用密码保护PowerPoint PPTX
  • 使用数字签名保护PowerPoint文档
  • 验证经过数字签名的PowerPoint演示文稿

>>你可以点击这里下载Aspose.Slides v20.10测试体验。(安装包仅提供部分功能,并设置限制,如需试用完整功能请申请免费授权

17一齐周年庆!整合所有格式的Aspose.Total永久授权正在火热促销中,乐享85折起!联系客服立马1分钟了解全部咨询!


使用C#中的密码保护PowerPoint PPTX

以下是使用密码保护PowerPoint PPTX演示文稿的步骤。

  • 使用Presentation类加载PPTX演示文稿。
  • 使用Presentation.ProtectionManager.Encrypt(String)方法加密演示文稿。
  • 使用Presentation.Save(String,SaveFormat)方法保存演示文稿。

下面的代码示例演示如何使用C#使用密码保护PPTX。

// Instantiate a Presentation object that represents a presentation fileusing (Presentation pres = new Presentation("presentation.pptx")){    // Protect with password    pres.ProtectionManager.Encrypt("password");    // Save presentation    pres.Save("protected-presentation.pptx", Export.SaveFormat.Pptx);}

使用C#中的数字签名保护PowerPoint文档

数字签名是一种在证书的帮助下保护数字信息的流行方法。MS PowerPoint演示文稿还支持数字签名以保护内容。以下是使用C#对PPTX文件进行数字签名的步骤。

  • 使用Presentation类加载PPTX演示文稿。
  • 创建一个DigitalSignature类的对象,并使用证书文件的路径和密码对其进行初始化。
  • 使用DigitalSignature.Comments属性添加注释。
  • 使用Presentation.DigitalSignatures.Add(DigitalSignature)方法签名演示。
  • 使用Presentation.Save(String,SaveFormat)方法保存演示文稿。

下面的代码示例演示如何使用C#在PowerPoint演示文稿中添加数字签名。

// Instantiate a Presentation object that represents a presentation fileusing (Presentation pres = new Presentation("presentation.pptx")){    // Create DigitalSignature object with PFX file and PFX password    DigitalSignature signature = new DigitalSignature("testsignature1.pfx", @"testpass1");    // Comment new digital signature    signature.Comments = "Aspose.Slides digital signing test.";    // Add digital signature to presentation    pres.DigitalSignatures.Add(signature);    // Save presentation    pres.Save("signed-presentation.pptx", Export.SaveFormat.Pptx);}

使用C#验证数字签名的演示文稿文档

.NET的Aspose.Slides也允许您验证演示文稿是否经过数字签名。此外,您可以检查文档是否被篡改或修改。以下是执行验证的步骤。

  • 使用Presentation类加载PowerPoint演示文稿。
  • 使用Presentation.DigitalSignatures.Count属性检查演示文稿是否包含数字签名。
  • 通过Presentation.DigitalSignatures集合进行迭代以访问每个数字签名。
  • 使用DigitalSignature.IsValid属性检查每个数字签名的有效性。

下面的代码示例演示如何使用C#在PowerPoint演示文稿中验证数字签名。

// Instantiate a Presentation object that represents a presentation fileusing (Presentation pres = new Presentation("presentation.pptx")){    // Check if presentation has digital signatures    if (pres.DigitalSignatures.Count > 0)    {        bool allSignaturesAreValid = true;        Console.WriteLine("Signatures used to sign the presentation: ");        // Check if all digital signatures are valid        foreach (DigitalSignature signature in pres.DigitalSignatures)        {            Console.WriteLine(signature.Certificate.SubjectName.Name + ", "                    + signature.SignTime.ToString("yyyy-MM-dd HH:mm") + " -- " + (signature.IsValid "VALID" : "INVALID"));            allSignaturesAreValid &= signature.IsValid;        }        if (allSignaturesAreValid)            Console.WriteLine("Presentation is genuine, all signatures are valid.");        else            Console.WriteLine("Presentation has been modified since signing.");    }}


还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年10月23日
下一篇 2020年10月24日

相关推荐

发表回复

登录后才能评论