Assign and Validate Digital Signatures

Introduction

Use the Digital Signature dialog to attach a digital signature. The Digital Signature dialog lists valid certificates. You can use the Digital Signature dialog to view certificates and to select the one you want to use. If a workbook has a digital signature, the name of the signature appears in the Certificate Name field. If you click the Remove button in the Digital Signature dialog, Microsoft Excel removes the digital signature as well.

How to Add Digital Signature for Excel

Aspose.Cells for Python via .NET provides the Aspose.Cells.DigitalSignatures namespace to perform the job (assign and validate digital signatures). The namespace has some useful features for adding and validating digital signatures.

Please see the following sample code that describes how you can perform the task using the Aspose.Cells for Python via .NET API.

from aspose.cells import Workbook
from aspose.cells.digitalsignatures import DigitalSignature, DigitalSignatureCollection
from datetime import datetime
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# dsc is signature collection contains one or more signature needed to sign
dsc = DigitalSignatureCollection()
# Cert must contain private key, it can be contructed from cert file or windows certificate collection. aa is password of cert
rawData = None
password = None
ds = DigitalSignature(rawData, password, "test for sign", datetime.now())
dsc.add(ds)
wb = Workbook()
# wb.SetDigitalSignature signs all signatures in dsc
wb.set_digital_signature(dsc)
wb.save(dataDir + r"newfile_out.xlsx")
# open the file
wb = Workbook(dataDir + r"newfile_out.xlsx")
print(wb.is_digitally_signed)
# Get digitalSignature collection from workbook
dsc = wb.get_digital_signature()
for dst in dsc:
print(dst.comments)
print(dst.sign_time)
print(dst.is_valid)

Advance topics