使用证书对 VBA 代码项目进行数字签名

使用 C# 中的证书对 VBA 代码项目进行数字签名

下面的示例代码说明了如何使用工作簿.VbaProject.Sign()方法。以下是示例代码的输入和输出文件。您可以使用任何 excel 文件和任何证书来测试此代码。

// 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");