Ajouter une signature numérique à un fichier Excel déjà signé
Scénarios d’utilisation possibles
Aspose.Cells fournit leWorkbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)méthode que vous pouvez utiliser pour ajouter une signature numérique à un fichier Excel déjà signé.
Ajouter une signature numérique à un fichier Excel déjà signé
L’exemple de code suivant montre comment utiliserWorkbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) méthode pour ajouter une signature numérique à un fichier Excel déjà signé. S’il vous plaît, vérifiez leexemple de fichier Excel utilisé dans ce code. Ce fichier est déjà signé numériquement. S’il vous plaît, vérifiez lefichier Excel de sortie généré par le code. Nous avons utilisé le certificat de démonstration nomméAsposeDemo.pfx dans ce code qui a un mot de passeposerLa capture d’écran montre l’effet de l’exemple de code sur l’exemple de fichier Excel après l’exécution.
Exemple de code
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Certificate file and its password | |
string certFileName = sourceDir + "AsposeDemo.pfx"; | |
string password = "aspose"; | |
//Load the workbook which is already digitally signed to add new digital signature | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourceDir + "sampleDigitallySignedByCells.xlsx"); | |
//Create the digital signature collection | |
Aspose.Cells.DigitalSignatures.DigitalSignatureCollection dsCollection = new Aspose.Cells.DigitalSignatures.DigitalSignatureCollection(); | |
//Create new certificate | |
System.Security.Cryptography.X509Certificates.X509Certificate2 certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certFileName, password); | |
//Create new digital signature and add it in digital signature collection | |
Aspose.Cells.DigitalSignatures.DigitalSignature signature = new Aspose.Cells.DigitalSignatures.DigitalSignature(certificate, "Aspose.Cells added new digital signature in existing digitally signed workbook.", DateTime.Now); | |
dsCollection.Add(signature); | |
//Add digital signature collection inside the workbook | |
workbook.AddDigitalSignature(dsCollection); | |
//Save the workbook and dispose it. | |
workbook.Save(outputDir + "outputDigitallySignedByCells.xlsx"); | |
workbook.Dispose(); | |