Signer numériquement un projet de code VBA avec un certificat

Signer numériquement un projet de code VBA avec un certificat en C#

Le code d’exemple suivant illustre comment utiliser la méthode Workbook.VbaProject.Sign(). Voici les fichiers d’entrée et de sortie du code d’exemple. Vous pouvez utiliser n’importe quel fichier Excel et n’importe quel certificat pour tester ce code.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
string password = "1234";
string pfxPath = sourceDir + "sampleDigitallySignVbaProjectWithCertificate.pfx";
string comment = "Signing Digital Signature using Aspose.Cells";
// Set Digital Signature
DigitalSignature digitalSignature = new DigitalSignature(File.ReadAllBytes(pfxPath), password, comment, DateTime.Now);
// Create workbook object from excel file
Workbook workbook = new Workbook(sourceDir + "sampleDigitallySignVbaProjectWithCertificate.xlsm");
// Sign VBA Code Project with Digital Signature
workbook.VbaProject.Sign(digitalSignature);
// Save the workbook
workbook.Save(outputDir + "outputDigitallySignVbaProjectWithCertificate.xlsm");