We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Digitally Sign code signing VBA macro using Java

How to digitally sign VBA macro in Java

@fsimon,

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");

Hope, this helps a bit.

There is alway a null pointer here
wb.getVbaProject().sign(signature);

@fsimon,

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 and other resource files to reproduce the issue. We will check your issue soon.