C# 实现PPT文档加密、解密以及重置密码的操作
所用工具:Spire.Presentation for. NET
Visual Studio 2013
工具使用说明:Spire.Presentation for .NET支持生成、写入、修改、转换、打印PPT等操作,这里我使用的是免费版的,使用前需要下载并安装,完成后需要添加引用dll文件到程序集中,同时也需添加using指令。
1.添加密码
using Spire.Presentation;namespace Security_PPT{ class Program { static void Main(string[] args) { //新建一个Presentation类实例,并加载需要加密的文档 Presentation presentation = new Presentation(); presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\test.pptx"); //加密文件,设置打开密码并保存文档 presentation.Encrypt("test"); presentation.SaveToFile("encrypt.pptx", FileFormat.Pptx2007); } }}
调试运行项目生成文件,如下图
打开文件,此时需要嵌入密码,正确输入密码后即可打开文档
2.重置密码
using Spire.Presentation;namespace ResetPassword_PPT{ class Program { static void Main(string[] args) { //创建一个Presentation类实例并加载已加密的文档 Presentation presentation = new Presentation(); presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\encrypt.pptx", FileFormat.Pptx2010, "test"); //解除原有密码,添加新密码 presentation.RemoveEncryption(); presentation.Protect("newtest"); //保存文档 presentation.SaveToFile("newresult.pptx", FileFormat.Pptx2010); } }}
同样的,调试运行程序生成文件
打开后输入新密码,这里可以选择可修改或者以只读方式查看文件
3.解除密码
上面描述的修改密码的方法中,若只是想解除密码而不新设置密码的话,只需删除掉添加新密码,即 presentation.Protect("newtest")这一行代码,调试运行后,生成的文档就没有密码保护了。
以上是对PPT文档进行加密、解密以及重设密码的操作,希望对你有所帮助。如果对你有用,欢迎转载(转载请注明出处)。
感谢浏览!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。