Free Support Forum - aspose.com

Aspse Word and digitally signed documents using a self generated cert

I am trying to create a unit test that generates an empty test document similar to the one found int eh Aspose Words example. I created a test cert using makecert.exe with the following line in the VS Command Promp

makecert.exe -sv MyKey.pvk -n "CN=MY DIGITAL KEY" MyKey.cer

I then converted it to a .psk file using the following line

pvk2pfx.exe -pvk MyKey.pvk -spc MyKey.cer -pfx MyPFX.pfx

After this was done I copied the .psk file into my .net console app and set the copy parameter to copy always so that the file is copied to the bin directory when I test the app in debug.

My console app then contains the following lines of code which tries to write a digitally signed pdf.

static void Main()

{

string MyDir = AppDomain.CurrentDomain.BaseDirectory;

// Create a simple document from scratch.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Test Signed PDF.");

// Load the certificate from disk.

// The other constructor overloads can be used to load certificates from different locations.

X509Certificate2 cert = new X509Certificate2(MyDir + "RpaKey.pfx", "");

Console.WriteLine("Loading certificate...");

// Pass the certificate and details to the save options class to sign with.

PdfSaveOptions options = new PdfSaveOptions();

options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(

cert,

"Test Signing",

"Aspose Office",

DateTime.Now);

Console.WriteLine("Creating digital signature details...");

try

{

// Save the document as PDF with the digital signature set.

doc.Save(MyDir + "Document.Signed Out.pdf", options);

Console.WriteLine("File saved successfully.");

}

catch (Exception ex)

{

Console.WriteLine("File write failed.");

Console.WriteLine(ex.Message);

if (ex.InnerException != null)

{

Console.WriteLine("");

Console.WriteLine(ex.InnerException);

}

}

Console.ReadKey();

}

However I keep getting an "invalid algorith specified" error with no inner exception. Has any one run into this problem? Have I missed a step? Any help is appreciated.

Hi there,


Thanks for your inquiry.

Are you able to attach your certificate here for testing? We will take a look closer look into this for you. Also, could you provide the specs of your testing machine, specifically what OS you are using?

Thanks,