Please see the document (with example) on how Aspose.Cells can digitally sign vba code project for your reference:
If you still could not make it work and find any issue, kindly do provide input file, digital signature file (.pfx) and output file. Also, paste your runnable code here to reproduce the issue, we will check it soon.
This is still not working, I try to sing the sample file with the sample cert and it’s password and it doesn’t work, I don’t know if it is a feature that is not implemented for .net core.
Attach the screenshot of the code that tries to sign the sample workbook. cert code.PNG (20.8 KB)
I tried again with a self certificate with the private key and still didn’t work.
This is a very important feature at the organizational level for trusting macros that passes by god knows who’s hands.
Again when I run the line
wb.VbaProject.Sign(digitalSignature);
it thows a System.NotImplementedException with the message “The method or operation is not implemented.”
@Guillermo.marcel,
We have investigated it more and found that VBA project signature is not supported in .NET Core yet. We have logged the issue in our database for a fix. Once, we will have some news for you, we will update you in this topic.
This issue has been logged as
CELLSNETCORE-49 - Sign VBA Project on .Net Core API
Please try our latest version/fix: Aspose.Cells for .NET v20.3.3 (attached)
Your issue should be fixed in it. See the sample code for your reference:
e.g Sample code:
string password = yourPFXPassword;
string pfxPath = yourPFXPath;
string comment = "Signing Digital Signature using Aspose.Cells";
//please use this constructor.
DigitalSignature ds = new DigitalSignature(File.ReadAllBytes(pfxPath), password, comment, DateTime.Now);
Workbook wb = new Workbook(srcFile.xlsm);
wb.VbaProject.Sign(ds);
wb.Save(outFile.xlsm);
Hello @Amjad_Sahi,
I have the same problem, we want to use Aspose on .NET Core 2.1 or 3.1 to run it on Linux but also get those exception for both ASP.NET Core 2.1 and 3.1:
Sadly I can’t download your attached v20.3.3 download, it shows me an error:
Sorry, this file is private. Only visible to topic owner and staff members.
Can you please allow me downloading the file too, so that I can try and test?
I’m also wondering about the version: You named it v20.3.3 and the latest one avaliable on NuGet is 20.9.0. Shouldn’t your fix already be included in 20.9.0 or is it an independent fork for .NET standard so that we can’t compare the version number from NuGet?
@Amjad_Sahi I tried it with v20.9 and still got the System.NotImplementedExeption exception like @Guillermo.marcel
My test code:
string excelFile = @"C:\...\testfile.xlsm";
string targetExcelFile = @"C:\...\testfile-signed.xlsm";
string certPath = @"C:\..\my-cert.pfx";
string certPw = "xxx";
var cert = new X509Certificate2(certPath, certPw);
var workbook = new Workbook(excelFile);
if (workbook.HasMacro)
{
var signature = new Aspose.Cells.DigitalSignatures.DigitalSignature(cert, "Aspose.Cells added new digital signature in existing digitally signed workbook.", DateTime.Now);
workbook.VbaProject.Sign(signature);
var stream = workbook.SaveToStream();
byte[] outputBuffer = stream.ToArray();
Console.WriteLine($"Bytes: {outputBuffer.Length}");
System.IO.File.WriteAllBytes(targetExcelFile, outputBuffer);
}
Also tried 20.4.0 assuming that this should be the first release containing your fixes from the v20.3.3 attached version, but still the same exception as in the latest 20.9.0.
Do you have an idea why I still get the not implemented exception in the latest release?
Please provide a sample VS.NET project (runnable) with .pfx (with password) and other template files, zip the project and post us or share via some file sharing service (e.g Google drive, dropbox), we will check it soon. Moreover, the following line of code is not right: var stream = workbook.SaveToStream();
Please save to XLSM stream via relevant Workbook.Save() overloads instead. Please note, Workbook.SaveToStream saves the file in older XLS file format.
By the way, did you test your scenario/ case on Windows if it works on it or not?
Using those cert from the docs it throws the same not implemented exception. So we know that it’s not related to my cert and you can use the demo one to reproduce it. I made you a complete VS project with those example cert/excel file from the docs:
@ahsaniqbalsidiqui This works great! Thank you very much for the fast help
Can you please add those bug with the constructor overload to our bug tracker and document this in the example article Digitally Sign a VBA Code Project with Certificate|Documentation ? That’s where I got the overload with X509Certificate2. I think this would be helpfull for others since the example code doesn’t work with those overload, only when passing the cert as byte array together with the password as you posted in the example.
Good to know that your issue is fixed now. And, sure, we will fix the sample code in the document. Please note, sample code shared in the post is proper way to sign vba code project.