Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6730929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:28:04+00:00 2026-05-26T10:28:04+00:00

I am trying to create a unit test that generates an empty test document

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:28:04+00:00Added an answer on May 26, 2026 at 10:28 am

    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:

    X509Certificate2 cert = new X509Certificate2(MyDir + "RpaKey.pfx", "");
    Console.WriteLine("Loading certificate...");
    

    to

    X509Certificate2 cert = new X509Certificate2(MyDir + "RpaKey.pfx", "");
    Console.WriteLine("Loading certificate... private key available ? {0}", cert.HasPrivateKey);
    

    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.

    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }
    

    so we’ll see if the error comes from Aspose or the BCL itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a unit test for a method that takes a
Working with Test::Unit and Shoulda. Trying to test Users.create . My understanding is that
I am trying to create a unit test similar to how I would have
I am trying to create a unit test that makes sure all of my
I'm trying to create a unit test to test the case for when the
Specifically, I'm trying to create a unit test for a method which requires uses
I'm trying to create an in-process unit test for my service to client interactions
I'm trying to create a mock HttpContextBase for unit test. var fakePrinciple = new
Im trying to unit test a class in some Java code that I've inherited.
I'm trying to figure out how to unit test my object that persists itself

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.