分配和验证数字签名
Contents
[
Hide
]
数字签名可确保工作簿文件有效并且没有人更改过它。您可以使用以下方法创建个人数字签名Microsoft Selfcert.exe或任何其他工具,或者您可以购买数字签名。创建数字签名后,您必须将其附加到您的工作簿。附加数字签名类似于密封信封。如果信封到达时是密封的,您可以在一定程度上保证没有人篡改过其中的内容。
介绍
使用“数字签名”对话框附加数字签名。数字签名对话框列出了有效的证书。您可以使用“数字签名”对话框查看证书并选择您要使用的证书。如果工作簿有数字签名,签名的名称会出现在证书名称场地。如果您单击去掉数字签名对话框中的按钮,Microsoft Excel 也会删除数字签名。
Aspose.Cells 提供了Aspose.Cells.DigitalSignatures命名空间来执行作业(分配和验证数字签名)。命名空间具有一些用于添加和验证数字签名的有用功能。
请参阅以下示例代码,它描述了如何使用 Aspose.Cells for .NET API 执行任务。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// dsc is signature collection contains one or more signature needed to sign | |
DigitalSignatureCollection dsc = new DigitalSignatureCollection(); | |
// Cert must contain private key, it can be contructed from cert file or windows certificate collection. aa is password of cert | |
X509Certificate2 cert = new X509Certificate2(dataDir + "mykey2.pfx", "aa"); | |
DigitalSignature ds = new DigitalSignature(cert, "test for sign", DateTime.Now); | |
dsc.Add(ds); | |
Workbook wb = new Workbook(); | |
// wb.SetDigitalSignature signs all signatures in dsc | |
wb.SetDigitalSignature(dsc); | |
wb.Save(dataDir + @"newfile_out.xlsx"); | |
// open the file | |
wb = new Workbook(dataDir + @"newfile_out.xlsx"); | |
System.Console.WriteLine(wb.IsDigitallySigned); | |
// Get digitalSignature collection from workbook | |
dsc = wb.GetDigitalSignature(); | |
foreach (DigitalSignature dst in dsc) | |
{ | |
System.Console.WriteLine(dst.Comments); //test for sign -OK | |
System.Console.WriteLine(dst.SignTime); //11/25/2010 1:22:01 PM -OK | |
System.Console.WriteLine(dst.IsValid); //True -OK | |
} |