We were trying to sign the excel file containing Macros, but post calling the below API calls and upon opening the excel file it still shows warning “Macros are disabled because the digital signature is invalid”
DigitalSignatureCollection dsCollection = new DigitalSignatureCollection();
DigitalSignature signature = new DigitalSignature(inputKeyStore, "Password12",
"Aspose.Cells added new digital signature in existing digitally signed workbook.",
DateTime.getNow());
dsCollection.add(signature);
workbook.addDigitalSignature(dsCollection);
String outputFile = ...
VbaProject vba = workbook.getVbaProject();
vba.sign(signature);
workbook.save(outputFile);
Does Aspose Cell support signing the Macros via Java, and if YES can you guide/advise
@sharad.gupta,
Yes, Aspose.Cells supports signing vba project. We added API VbaProject.sign(DigitalSignature digitalSignature) for Java version. Also, two Bouncy Castle libs are needed: bcprov-jdk15on-1.60.jar and bcpkix-jdk15on-1.60.jar which can be found in the release archive folder (".\JDK 1.6\lib").
Here is a sample code for your reference.
e.g.
Sample code:
String pfxFilePath = "...";
String pfxPassowrd = "...";
// Load the certificate into an instance of InputStream
InputStream inStream = new FileInputStream(pfxFilePath);
// 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, pfxPassowrd.toCharArray());
inStream.close();
// Create an instance of DigitalSignature and pass the instance of KeyStore, password, comments and time
DigitalSignature signature = new DigitalSignature(inputKeyStore, pfxPassowrd, "test for VBA signature",
DateTime.getNow());
Workbook wb = new Workbook();
wb.getWorksheets().get(0).getCells().get("A1").putValue("test VBA signature in Java");
wb.getVbaProject().sign(signature);
wb.save("output.xlsm");
Please try our latest version/fix: Aspose.Cells for Java v22.4 (if you are not already using it). If you still find the issue, kindly provide complete Java program/sample code with pfx, other resource files and Excel files to reproduce the issue. We will check your issue soon.
PS. please zip the Excel and other resource files prior attaching here.