証明書を使用して VBA コード プロジェクトにデジタル署名する
Contents
[
Hide
]
Aspose.Cells を使用して VBA コード プロジェクトにデジタル署名できます。[Workbook.VbaProject.Sign()](https://reference.aspose.com/cells/java/com.aspose.cells/vbaproject#sign(com.aspose.cells.DigitalSignature)) 方法。次の手順に従って、Excel ファイルが証明書でデジタル署名されているかどうかを確認してください。
- クリックビジュアルベーシックからデベロッパー開くタブVisual Basic for Applications IDE
- クリックツール > デジタル署名…のVisual Basic for Applications IDE
そして、それはデジタル署名フォームドキュメントが証明書でデジタル署名されているかどうかを示します。
C# の証明書を使用して VBA コード プロジェクトにデジタル署名する
次のサンプル コードは、[Workbook.VbaProject.Sign()](https://reference.aspose.com/cells/java/com.aspose.cells/vbaproject#sign(com.aspose.cells.DigitalSignature)) 方法。サンプル コードの入力ファイルと出力ファイルを次に示します。任意の 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-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"); |