AsposeWordsの例にあるような空のテストドキュメントを生成する単体テストを作成しようとしています。VSコマンドプロンプトで次の行を使用してmakecert.exeを使用してテスト証明書を作成しました
makecert.exe -sv MyKey.pvk -n "CN=MY DIGITAL KEY" MyKey.cer
次に、次の行を使用して.pvkファイルに変換しました
pvk2pfx.exe -pvk MyKey.pvk -spc MyKey.cer -pfx MyPFX.pfx
これが完了したら、.pfxファイルを.netコンソールアプリにコピーし、copyパラメーターを常にcopyに設定して、デバッグでアプリをテストするときにファイルがbinディレクトリにコピーされるようにします。
次に、私のコンソールアプリには、デジタル署名された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();
}
ただし、内部例外なしで「無効なアルゴリズムが指定されました」というエラーが発生し続けます。誰かがこの問題に遭遇しましたか?私は一歩を逃したことがありますか?どんな助けでも大歓迎です。