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

Free Support Forum - aspose.com

Sign VBA Project on .Net Core API

Some Context, I’m working on an application with .NetCore 2.2 with the NuGet version of the Aspose.Cells Version=“20.1.0”.

In this project I Create from scratch a new Workbook with
var workbook = new Workbook();

The problem comes when I try to Sign the VBA Project
Capture.PNG (11.1 KB)

This code throws a System.NotImplementedExeption with the message: “The method or operation is not implemented.”

Here comes some cert info:
cert.PNG (32.7 KB)

I’m concern that the lack of Private Key must be the issue

1 Like

@Guillermo.marcel,

Thanks for the screenshots.

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
1 Like

@Guillermo.marcel,

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

Let us know your feedback.
Aspose.Cells20.3.3 For .NetStandard20.Zip (5.3 MB)

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:

grafik.png (4.7 KB)

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?

@Th3Dan,

Yes, please try using our latest version/fix: Aspose.Cells for .NET v20.9 and let us know your feedback.

@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);
            }

My csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Aspose.Cells" Version="20.9.0" />
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
  </ItemGroup>
</Project>

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?

@Th3Dan,

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?

1 Like

@Amjad_Sahi Thank you for the tip with SaveToStream(), now I changed it to

var stream = new MemoryStream();
workbook.Save(stream, SaveFormat.Xlsm);

I can’t test it yet since the not implemented exception occurs before. I’m not allowed to submit our pfx cert. But I found a demo cert and excel file in our documentation: https://docs.aspose.com/cells/net/digitally-sign-a-vba-code-project-with-certificate/

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:

AsposeTest_Support.zip (1.2 MB)

Also tried this on Windows 10 with Visual Studio 2019, it produces the same exception.

@Th3Dan,
You may please try the following sample code and share the feedback.

    string password = "1234";
    string pfxPath = "SampleCert.pfx";
    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("Source.xlsm");
    wb.VbaProject.Sign(ds);

    wb.Save("Source.xlsm");
1 Like

@ahsaniqbalsidiqui This works great! Thank you very much for the fast help :slight_smile:
Can you please add those bug with the constructor overload to our bug tracker and document this in the example article https://docs.aspose.com/cells/net/digitally-sign-a-vba-code-project-with-certificate/ ? 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.

@Th3Dan,

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.

1 Like

@Th3Dan,

The sample code in the document is updated now. Please remove browser’s cache if you still see the older code in the document.

1 Like