使用证书对 VBA 代码项目进行数字签名
Contents
[
Hide
]
您可以使用 Aspose.Cells 及其代码对您的 VBA 代码项目进行数字签名工作簿.VbaProject.Sign()方法。请按照以下步骤检查您的 excel 文件是否使用证书进行了数字签名。
- 点击视觉基础来自开发商要打开的选项卡Visual Basic for Applications 集成开发环境
- 点击工具 > 数字签名…的Visual Basic for Applications 集成开发环境
它会显示数字签名表显示文档是否使用证书进行数字签名。
使用 C# 中的证书对 VBA 代码项目进行数字签名
下面的示例代码说明了如何使用工作簿.VbaProject.Sign()方法。以下是示例代码的输入和输出文件。您可以使用任何 excel 文件和任何证书来测试此代码。
- 源 Excel 文件在示例代码中使用。
- 示例 pfx 文件创建数字签名。请在您的计算机上安装它以运行此代码。它的密码是1234。
- 输出Excel文件由示例代码生成。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |