Digitale Signatur eines VBA Codeprojekts mit Zertifikat

Digitale Signatur eines VBA-Codeprojekts mit Zertifikat in C#

Der folgende Beispielcode veranschaulicht, wie die Methode Workbook.VbaProject.Sign() verwendet wird. Hier sind die Eingabe- und Ausgabedateien des Beispielcodes. Sie können beliebige Excel-Datei und beliebiges Zertifikat verwenden, um diesen Code zu testen.

  • Quell-Excel-Datei, die im Beispielcode verwendet wird.
  • Beispiel-PFX-Datei zur Erstellung einer digitalen Signatur. Bitte installieren Sie diese auf Ihrem Computer, um diesen Code auszuführen. Das Kennwort lautet 1234.
  • Ausgabe-Excel-Datei, die vom Beispielcode generiert wurde.
// 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");