証明書でVBAコードプロジェクトにデジタル署名する
Contents
[
Hide
]
Aspose.Cellsを使用してVBAコードプロジェクトにデジタル署名することができます。 Workbook.VbaProject.Sign() 方法を使用してください。 Excelファイルが証明書でデジタル署名されているかどうかを確認するには、次の手順に従ってください。
- 開発タブからVisual BasicをクリックしてVisual Basic for Applications IDEを開きます
- Visual Basic for Applications IDEのツール > **デジタル署名…**をクリック
そうするとデジタル署名フォームが表示され、ドキュメントが証明書でデジタル署名されているかどうかが表示されます。
C#でVBAコードプロジェクトに証明書でデジタル署名する
次のサンプルコードは、Workbook.VbaProject.Sign() 方法を使用する方法を示しています。サンプルコードの入出力ファイルは次のとおりです。任意のExcelファイルと任意の証明書を使用してこのコードをテストできます。
- サンプルのExcelファイル(5115028.xlsm)
- サンプルpfxファイル(5115039.pfx)でデジタル署名を作成します。このコードを実行するためにこのファイルをコンピューターにインストールしてください。パスワードは1234です。
- サンプルコードによって生成された出力Excelファイル(5115029.xlsm)
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-Java | |
String password = "1234"; | |
String pfxPath = sourceDir + "sampleDigitallySignVbaProjectWithCertificate.pfx";; | |
String comment = "Signing Digital Signature using Aspose.Cells"; | |
// Load the certificate into an instance of InputStream | |
InputStream inStream = new FileInputStream(pfxPath); | |
// Create an instance of KeyStore with PKCS12 cryptography | |
KeyStore inputKeyStore = KeyStore.getInstance("PKCS12"); | |
// Use the KeyStore.load method to load the certificate stream and its password | |
inputKeyStore.load(inStream, password.toCharArray()); | |
inStream.close(); | |
// Create an instance of DigitalSignature and pass the instance of KeyStore, password, comments and time | |
DigitalSignature signature = new DigitalSignature(inputKeyStore, password, comment, | |
DateTime.getNow()); | |
Workbook wb = new Workbook(sourceDir + "sampleDigitallySignVbaProjectWithCertificate.xlsm"); | |
wb.getVbaProject().sign(signature); | |
wb.save(outputDir + "outputDigitallySignVbaProjectWithCertificate.xlsm"); |