I am trying to create a unit test that generates an empty test document similar to the one found in the 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 .pvk file using the following line
pvk2pfx.exe -pvk MyKey.pvk -spc MyKey.cer -pfx MyPFX.pfx
After this was done I copied the .pfx 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.
Never used Aspose myself but you should first ensure that your conversion from the PVK to the PFX format worked like you expected.
Change this:
to
Note that it likely did success since there was no exception – but that will at least confirm the first part of your process is valid 🙂
If this shows true then you should update your question to show the full stack trace from your exception, e.g.
so we’ll see if the error comes from Aspose or the BCL itself.