欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C# / VB.NET 添加、删除PPT幻灯片中的数字签名

程序员文章站 2022-03-28 14:38:28
...

本文介绍如何通过C#及VB.NET代码来添加数字签名到PPT幻灯片文档,以及如何将文档中的数字签名删除。

辅助工具:

  • Spire.Presentation.dll (dll版本为5.11.2)

注意:2种dll文件下载及引用方法:

方法1下载包,解压到指定路径,并在VS程序中添加引用Spire.Presentation.dll文件;

方法2:通过Nuget下载。

 

 

 

示例1—添加数字签名到PPT文档

using Spire.Presentation;
using System;
using System.Security.Cryptography.X509Certificates;

namespace AddDigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载PPT测试文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("test.pptx");

            //添加数字签名
            X509Certificate2 x509 = new X509Certificate2("cer.pfx", "123654");
            ppt.AddDigitalSignature(x509, "Manager", DateTime.Now);

            //保存文档
            ppt.SaveToFile("AddDigitalSignature.pptx", FileFormat.Pptx2013);
            System.Diagnostics.Process.Start("AddDigitalSignature.pptx");
        }
    }
}

 

Imports Spire.Presentation
Imports System.Security.Cryptography.X509Certificates

Namespace AddDigitalSignature
	Class Program
		Private Shared Sub Main(args As String())
			'加载PPT测试文档
			Dim ppt As New Presentation()
			ppt.LoadFromFile("test.pptx")

			'添加数字签名
			Dim x509 As New X509Certificate2("cer.pfx", "123654")
			ppt.AddDigitalSignature(x509, "Manager", DateTime.Now)

			'保存文档
			ppt.SaveToFile("AddDigitalSignature.pptx", FileFormat.Pptx2013)
			System.Diagnostics.Process.Start("AddDigitalSignature.pptx")
		End Sub
	End Class
End Namespace

 

示例2—删除PPT文档中的数字签名

using Spire.Presentation;

namespace RemoveDigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载包含数字签名的PPT文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("AddDigitalSignature.pptx");

            //判断文档是否已签名
            if (ppt.IsDigitallySigned == true)
            {
                //移除所有签名
                ppt.RemoveAllDigitalSignatures();
            }

            //保存文档
            ppt.SaveToFile("RemoveDigitalSignature.pptx", FileFormat.Pptx2013);
            System.Diagnostics.Process.Start("RemoveDigitalSignature.pptx");
        }
    }
}

 

 

Imports Spire.Presentation

Namespace RemoveDigitalSignature
	Class Program
		Private Shared Sub Main(args As String())
			'加载包含数字签名的PPT文档
			Dim ppt As New Presentation()
			ppt.LoadFromFile("AddDigitalSignature.pptx")

			'判断文档是否已签名
			If ppt.IsDigitallySigned = True Then
				'移除所有签名
				ppt.RemoveAllDigitalSignatures()
			End If

			'保存文档
			ppt.SaveToFile("RemoveDigitalSignature.pptx", FileFormat.Pptx2013)
			System.Diagnostics.Process.Start("RemoveDigitalSignature.pptx")
		End Sub
	End Class
End Namespace