IronPDF ハウツー HSM による PDF 署名 How to Digitally Sign PDFs with C# using HSM Curtis Chau 更新日:11月 3, 2025 Download IronPDF NuGet Download テキストの検索と置換 テキストと画像のスタンプ Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English Adding a signature to a PDF document is a common requirement in many applications. However, mission-critical applications require a higher level of security where the key itself cannot be tampered with. A normal signing operation with a .pfx file is akin to having a master key at your house. The application needs to load the key into your computer's memory to sign the document. If the computer itself is compromised, the key may be stolen. A far more secure alternative is using a Hardware Security Module (HSM). With an HSM (like your USB token), the private key is generated inside the device and is physically incapable of ever leaving it. This process is akin to bringing the document to the bank. The application provides a PIN, and the "bank manager" (the HSM) takes the document into the vault, stamps it with the key, and hands the stamped document back. The main aspect is that the key never leaves the vault. This provides an additional security measure, as the key cannot be copied or stolen. How to digitally Sign PDFs with HSM Download the IronPDF C# library for signing PDFs with HSM Import your existing HSM or simulate it with other libraries Create a new UsbPkcs11HsmSigner object Sign and save the PDF with SignAndSave Verify the PDF output and certificate with a PDF viewer 今日あなたのプロジェクトでIronPDFを無料トライアルで使用開始。 最初のステップ: 無料で始める Signing with an HSM Signing with an HSM typically requires a physical device, such as a USB token, that the application interacts with. IronPDF is fully compatible with these operations, as both the library and standard HSMs often use PKCS#11 as a common API. For demonstrative purposes regarding IronPDF's functionality with HSMs, this guide will use a simulated HSM instead of a physical one. In a production or live testing environment, you should not use this simulation. Instead, you must use your actual HSM. To run this simulation, you must first install SoftHSM, OpenSSL, and OpenSC to generate the necessary key and token. For more information on how to utilize SoftHSM, please refer to their public GitHub repository. We'll start by creating a PDF from an HTML string. In the example below, we define the paths and credentials for our simulated SoftHSM. This includes providing the absolute path to the SoftHSM .dll library file and the .crt certificate file that you created. Next, we specify the output path, which in this instance is output.pdf. Furthermore, we define three strings: hsmTokenLabel, hsmPin, and hsmKeyLabel. These strings are case-sensitive and must exactly match the credentials you created when generating the token and certificate with SoftHSM. Afterwards, we initialize the UsbPkcs11HsmSigner object, passing the SoftHSM library path, PIN, token label, and key label as parameters. We additionally create a PdfSignatureImage to add a visual representation of the signature onto the document. Finally, we call SignAndSave, which uses the hsmSigner we configured to sign the document and save it to the specified output path. Code :path=/static-assets/pdf/content-code-examples/how-to/signing-with-hsm.cs using IronPdf; using IronPdf.Signing; using IronSoftware.Pdfium.Signing; using System.Drawing; ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Testing</h1>"); // Define Paths and Credentials string softhsmLibraryPath = @"D:\SoftHSM2\lib\softhsm2-x64.dll"; // These MUST match what you created string hsmTokenLabel = "MyTestToken"; string hsmPin = "123456"; string hsmKeyLabel = "my-key"; // The label for the key *inside* the token // Create the HsmSigner object. UsbPkcs11HsmSigner hsmSigner = new UsbPkcs11HsmSigner( softhsmLibraryPath, hsmPin, hsmTokenLabel, hsmKeyLabel ); // Create the Signature Image string signatureImagePath = "IronSoftware.png"; PdfSignatureImage sigImage = new PdfSignatureImage(signatureImagePath, 0, new Rectangle(50, 50, 150, 150)); // Sign PDF with HSM pdf.SignAndSave("signedWithHSM.pdf", hsmSigner); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel The UsbPkcs11HsmSigner additionally takes two optional parameters, the digestAlgorithm and signingAlgorithm. By default, they are set to SHA256 and RSA. Output Below is the output generated. As you can see, it displays the signature field and confirms that it is signed with the certificate we generated. Troubleshooting If you encounter the error shown below while running the code example, follow these troubleshooting steps to debug and verify your configuration. This CKR_GENERAL_ERROR commonly occurs when the program cannot find the SoftHSM configuration file or when the .NET application is running as a 32-bit process while the SoftHSM library is 64-bit. Changing the Platform Target A common cause for this error is an architecture mismatch. Your C# application must run as a 64-bit process to match the 64-bit SoftHSM library (softhsm2-x64.dll). In your Visual Studio project properties, change the Platform target from 'Any CPU' or 'x86' to 'x64' to ensure compatibility. Setting the Environment Variable Another common cause of error is that the program cannot find the .conf file in SoftHSM. You must tell the library where to look by setting a system-wide environment variable. Create a new variable named SOFTHSM2_CONF and set its value to the full path of your configuration file (e.g., D:\SoftHSM2\etc\softhsm2.conf). Afterwards, remember to restart Visual Studio after making the changes. Additionally, you can verify whether the variable is found by adding this line. Console.WriteLine($"Verifying variable: {Environment.GetEnvironmentVariable("SOFTHSM2_CONF")}"); Console.WriteLine($"Verifying variable: {Environment.GetEnvironmentVariable("SOFTHSM2_CONF")}"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel If the console output returns blank, then the program can't find the environment variable. You must set it, restart Visual Studio or your computer, and try again. よくある質問 ハードウェア セキュリティ モジュール (HSM) とは何ですか? また、なぜ PDF の署名に使用されるのですか? ハードウェアセキュリティモジュール(HSM)は、デジタルキーの管理と暗号化・復号化機能を実行するために使用される物理デバイスです。PDFへの署名に使用され、署名プロセスの安全性と様々な標準への準拠を確保することで、セキュリティを強化します。 C# で PDF に署名するための HSM を構成するにはどうすればよいですか? C# で PDF に署名するために HSM を構成するには、適切なドライバーとソフトウェアを使用して HSM を設定し、システムに接続されていることを確認し、IronPDF を使用して C# アプリケーション内で署名プロセスを構成する必要があります。 IronPDF を使用して PDF にデジタル署名するには、どのような手順が必要ですか? IronPDF を使用して PDF にデジタル署名するには、まず HSM を初期化し、C# コード内でデジタル署名を構成し、IronPDF の署名機能を使用して PDF ドキュメントに署名を適用する必要があります。 IronPDF を使用して、他の種類のデジタル証明書で PDF に署名できますか? はい、IronPDF は HSM で管理されている証明書だけでなく、さまざまな種類のデジタル証明書による PDF 署名をサポートしています。これには、ソフトウェアキーストアに保存されている証明書も含まれます。 PDF 署名に IronPDF を使用する利点は何ですか? IronPDFは、PDF署名用の分かりやすいAPIを提供しており、C#アプリケーションにデジタル署名を簡単に統合できます。HSMで管理されるものも含め、様々な証明書タイプをサポートし、柔軟性とセキュリティを確保します。 IronPDF で作成された PDF 署名を検証することは可能ですか? はい、IronPDF を使用して PDF に署名すると、デジタル署名をサポートする標準の PDF リーダーを使用して署名を検証できるため、ドキュメントの整合性と信頼性が保証されます。 IronPDF を使用して PDF に署名するには、プログラミング経験が必要ですか? IronPDF を使用して PDF に署名するには、署名プロセスを管理し、HSM を適切に構成するためのコードを記述する必要があるため、C# の基本的なプログラミング知識があることが推奨されます。 HSM と IronPDF を統合する場合、どのようなサポートが受けられますか? Iron Software は、HSM と IronPDF を統合し、デジタル署名機能のスムーズなセットアップと操作を保証するためのドキュメントと技術サポートを提供します。 Curtis Chau 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 準備はいいですか? Nuget ダウンロード 16,133,208 | バージョン: 2025.11 ただ今リリースされました 試用ライセンスキーがメールで送信されました。 総ダウンロード数: 16,133,208 ライセンスを見る