DigitalSignatureCollection Class
Provides a collection of digital signatures attached to a document.
Inheritance Hierarchy
SystemObject
  Aspose.Cells.DigitalSignaturesDigitalSignatureCollection

Namespace: Aspose.Cells.DigitalSignatures
Assembly: Aspose.Cells (in Aspose.Cells.dll) Version: 19.11.0.0 (19.11)
Syntax
public class DigitalSignatureCollection : IEnumerable

The DigitalSignatureCollection type exposes the following members.

Constructors
  NameDescription
Public methodDigitalSignatureCollection
The constructor of DigitalSignatureCollection.
Methods
  NameDescription
Public methodAdd
Add one signature to DigitalSignatureCollection.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator
Get the enumerator for DigitalSignatureCollection, this enumerator allows iteration over the collection
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Examples
The following example shows how to create digital signature
[C#]
internal void ValidateSignature()
{
   Workbook wb = new Workbook(@"c:\newfile.xlsx");
   //wb.IsDigitallySigned is true when the workbook is signed already.
   System.Console.WriteLine(wb.IsDigitallySigned);
   //get digitalSignature collection from workbook
   DigitalSignatureCollection dsc = wb.GetDigitalSignature();
   foreach (DigitalSignature ds in dsc)
   {
       System.Console.WriteLine(ds.Comments);
       System.Console.WriteLine(ds.SignTime);
       System.Console.WriteLine(ds.IsValid);
   }
}
internal void SignSignature()
{
   //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.
   //123456 is password of cert
   X509Certificate2 cert = new X509Certificate2("c:\\mykey2.pfx", "123456");
   DigitalSignature ds = new DigitalSignature(cert, "test for sign", DateTime.Now);
   dsc.Add(ds);
   Workbook wb = new Workbook();
   //wb.SetDigitalSignature sign all signatures in dsc
   wb.SetDigitalSignature(dsc);
   wb.Save(@"c:\newfile.xlsx");
}

[Visual Basic]
   Sub ValidateSignature()
   Dim workbook As Workbook = New Workbook("c:\newfile.xlsx")
   'Workbook.IsDigitallySigned is true when the workbook is signed already.
   System.Console.WriteLine(workbook.IsDigitallySigned)
   'get digitalSignature collection from workbook
   Dim dsc As DigitalSignatureCollection = workbook.GetDigitalSignature()
   Dim ds As DigitalSignature
   For Each ds In dsc
       System.Console.WriteLine(ds.Comments)
       System.Console.WriteLine(ds.SignTime)
       System.Console.WriteLine(ds.IsValid)
   Next
End Sub

Sub SignSignature()
   'dsc is signature collection contains one or more signature needed to sign
   Dim dsc As DigitalSignatureCollection = New DigitalSignatureCollection()
   'cert must contain private key, it can be contructed from cert file or windows certificate collection.
   Dim cert As X509Certificate2 = New X509Certificate2("c:\mykey2.pfx", "123456")
   'create a signature with certificate, sign purpose and sign time
   Dim ds As DigitalSignature = New DigitalSignature(cert, "test for sign", DateTime.Now)
   dsc.Add(ds)
   Dim workbook As Workbook = New Workbook()
   'workbook.SetDigitalSignature sign all signatures in dsc
   workbook.SetDigitalSignature(dsc)
   workbook.Save("c:\newfile.xlsx")
End Sub
See Also