USING IRONPDF x509certificate2 Add Digital Signature to PDF Programmatically Curtis Chau 更新:2025年8月20日 下載 IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 x509certificate2可用於取得現有憑證的重要資訊(有效日期、發行者等)。 IronPDF 讓您可以使用 C# 對 PDF 進行數位簽章。 您可以建立新文件或簽署現有PDF文件。只需一行程式碼即可,如下簡單步驟所示。 您的企業在PDF安全和合規性方面的年度訂閱費用過高。不妨考慮一下IronSecureDoc ,它提供SaaS服務管理解決方案,例如數位簽章、內容編輯、加密和保護,所有服務只需一次性付費。立即試用! ## 如何在 C# 中新增數位 PDF 簽名 安裝 C# 程式庫以向 PDF 新增數位簽章。 使用 Windows Form 更好地可視化過程 將數位簽章和私鑰傳遞給PdfSignature類 使用SignPdfFile方法開啟並簽署現有 PDF 檔案。 檢查第 4 步中指定目錄中的簽名 PDF 步驟 1 1. 取得 IronPDF 首先,將 IronPDF 安裝到您的 Visual Studio 專案中。 您可以選擇任何對您來說更方便的方式獲取,無論是透過DLL 下載還是從NuGet 網站獲取。 在 Visual Studio 中開啟 C# 函式庫,然後我們來新增一個簽章。 # Product Installation using NuGet nuget install IronPdf # Product Installation using NuGet nuget install IronPdf SHELL 操作指南 2. 理解數位簽名 數位簽名就像電子駕駛執照或護照,可以證明您的身份。 數位身分通常包含您的姓名和電子郵件地址、頒發該身分的組織名稱、序號和到期日。 數位身分用於憑證安全性和數位簽章。 這需要使用 Adobe Acrobat 建立才能正常運作。 3. 對 PDF 檔案進行數位簽名 現在,讓我們來看看如何使用 C# 建立x509certificate2來對 PDF 進行數位簽章。 如今,IronPDF 庫提供了一種簡單的方法來應用簽名,只需一行程式碼即可節省時間和精力。 在開發過程中,您可以免費使用它來測試您的作品。 然後,確定你的項目。 您是要建立新文件還是簽署現有PDF文件? 在下面的程式碼範例中,使用 C# 表單允許使用者選擇所需的 PDF 文件,只需單擊即可接收數位簽章。 需要準備一個.pfx file (個人資訊交換格式),該檔案用於借助私鑰傳輸憑證。 PdfSignature類別中的SignPdfFile(FileName)方法是數位簽章的主要方法。 只需選擇所需文件即可。 using System.Drawing; using System.Windows.Forms; using IronPdf; namespace DigitalSign { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, System.EventArgs e) { // Open a dialog to select the desired PDF file if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; // Display selected PDF path in the textbox } } private void button2_Click(object sender, System.EventArgs e) { // Use PdfSignature method to digitally sign the selected PDF new PdfSignature("Ironpdf.pfx", "123456").SignPdfFile(textBox1.Text); // Provide user feedback that signing is complete label3.Text = "Completed!"; label3.BackColor = Color.LightGreen; label3.ForeColor = Color.Black; } } } using System.Drawing; using System.Windows.Forms; using IronPdf; namespace DigitalSign { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, System.EventArgs e) { // Open a dialog to select the desired PDF file if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; // Display selected PDF path in the textbox } } private void button2_Click(object sender, System.EventArgs e) { // Use PdfSignature method to digitally sign the selected PDF new PdfSignature("Ironpdf.pfx", "123456").SignPdfFile(textBox1.Text); // Provide user feedback that signing is complete label3.Text = "Completed!"; label3.BackColor = Color.LightGreen; label3.ForeColor = Color.Black; } } } Imports System.Drawing Imports System.Windows.Forms Imports IronPdf Namespace DigitalSign Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Open a dialog to select the desired PDF file If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then textBox1.Text = openFileDialog1.FileName ' Display selected PDF path in the textbox End If End Sub Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Use PdfSignature method to digitally sign the selected PDF Call (New PdfSignature("Ironpdf.pfx", "123456")).SignPdfFile(textBox1.Text) ' Provide user feedback that signing is complete label3.Text = "Completed!" label3.BackColor = Color.LightGreen label3.ForeColor = Color.Black End Sub End Class End Namespace $vbLabelText $csharpLabel 以上 C# 程式碼表示一個 Windows 窗體應用程序,其中: 按鈕用於開啟文件對話框,以便選擇 PDF 文件。 A second button triggers the signing of the selected PDF using a predefined `.pfx` file and password. 標籤已更新,以確認簽約流程已完成。 4. 審核文件簽名 如下面的輸出所示,只要選取 PDF 檔案並按一下"匯入簽章"按鈕,即可成功對文件進行數位簽章。 使用 IronPDF,只需要一行程式碼。 ! x509certificate2 以程式設計方式為 PDF 新增數位簽名,圖 1: ! x509certificate2 以程式設計方式為 PDF 新增數位簽名,圖 2: IronPDF是使用 C# 處理 PDF 相關任務的完美工具。 IronPDF 為開發者提供了將 PDF 文件渲染成圖像以及從 PDF 中提取文字和內容的方法。 此外,IronPDF 還能夠在 PDF 中渲染圖表,使用 IronBarcode 庫添加條碼,透過密碼、浮水印增強安全性,甚至可以以程式設計方式處理 PDF 表單。 圖書館快速訪問 ### API 參考 請閱讀 IronPDF 文件和完整的函數清單。 API 參考 常見問題解答 如何以 C# 程式化的方式在 PDF 上加入數位簽章? 若要在 C# 中為 PDF 加入數位簽章,請使用 IronPDF。首先,透過 NuGet 安裝 IronPDF 或下載 DLL。然後,使用 `x509certificate2` 類別來處理證書,並使用 `PdfSignature` 類別來套用簽章,並使用 `SignPdfFile` 方法來套用 `.pfx` 檔案與密碼。 PDF 中數位簽章的意義是什麼? PDF 中的數位簽章透過驗證寄件者的身份提供了額外的保護層,就像電子護照一樣。它們可確保文件的真實性和完整性,防止未經授權的修改。 使用 IronPDF 簽署 PDF 是否容易? 是的,使用 IronPDF 簽署 PDF 簡單直接。它只需要一行代碼,使用 `SignPdfFile` 方法,就可以簡單地將數位簽章整合到 PDF 檔案中。 x509certificate2` 類在數位簽章中扮演什麼角色? C# 中的 `x509certificate2` 類用於管理和處理 X.509 證書,這對應用數位簽章至關重要。它提供證書的相關資訊,並與 IronPDF 一起用於簽署 PDF。 在購買之前,我可以免費試用 IronPDF 嗎? 是的,IronPDF 可在開發過程中免費使用,以便在做出購買決定之前測試其功能,包括數位簽章。 我應該使用何種檔案格式來傳輸包含數位簽章用私密金鑰的證書? 若要傳輸附有私密金鑰的憑證,請使用 `.pfx` 檔案格式,也就是所謂的「個人資訊交換格式」。 如何在 Visual Studio 專案中安裝 IronPDF? 透過直接下載 DLL 或使用 NuGet `nuget install IronPdf` 指令,在您的 Visual Studio 專案中安裝 IronPDF。 SignPdfFile` 方法的目的是什麼? IronPDF 中的「SignPdfFile」方法用於使用指定的憑證和私密金鑰對 PDF 檔案進行數位簽章,以增強文件的安全性。 在添加数字签名时,IronPDF 是否完全支持 .NET 10? 是的,IronPDF 與 .NET 10 完全相容,所有的數位簽章功能--包括 `PdfSignature`、`x509certificate2`、`Sign` 和 `SignPdfFile` 方法--都無需額外設定即可運作。IronPDF 支援 .NET 10 以及許多其他 .NET 版本(例如 .NET 9、8、7 等)。 在使用 IronPDF 的數位簽章功能之前,是否有任何先決條件或 .NET 版本要求? IronPDF 的數位簽章功能需要 .NET 版本 5 或更高 - 包括 .NET 10、.NET 9、.NET Core 和 .NET Standard。對於較早的框架或不支援的版本,該函式庫可能無法提供完全相容性,或可能需要額外的相依性。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 相關文章 更新2026年1月22日 How to Create PDF Documents in .NET with IronPDF: Complete Guide Discover effective methods to create PDF files in C# for developers. Enhance your coding skills and streamline your projects. Read the article now! 閱讀更多 更新2026年1月21日 How to Merge PDF Files in VB.NET: Complete Tutorial Merge PDF VB NET with IronPDF. Learn to combine multiple PDF files into one document using simple VB.NET code. Step-by-step examples included. 閱讀更多 更新2026年1月21日 C# PDFWriter Tutorial: Create PDF Documents in .NET Learn to create PDFs efficiently using C# PDFWriter with this step-by-step guide for developers. Read the article to enhance your skills today! 閱讀更多 Create PDF in C# 14: Advanced Guide Using Visual Studio Code in 2025Generating PDF Files in C# (2026 Guide)
更新2026年1月22日 How to Create PDF Documents in .NET with IronPDF: Complete Guide Discover effective methods to create PDF files in C# for developers. Enhance your coding skills and streamline your projects. Read the article now! 閱讀更多
更新2026年1月21日 How to Merge PDF Files in VB.NET: Complete Tutorial Merge PDF VB NET with IronPDF. Learn to combine multiple PDF files into one document using simple VB.NET code. Step-by-step examples included. 閱讀更多
更新2026年1月21日 C# PDFWriter Tutorial: Create PDF Documents in .NET Learn to create PDFs efficiently using C# PDFWriter with this step-by-step guide for developers. Read the article to enhance your skills today! 閱讀更多