Zum Fußzeileninhalt springen
IRONPDF NUTZEN

x509certificate2 Digitale Signatur programmgesteuert zu PDF hinzufügen

x509certificate2 can be used to get important information about an existing certificate (valid dates, issuer, etc.). IronPDF allows you to digitally sign a PDF using C#. You can create a new document or sign an existing PDF file. It requires just a single line of code, as illustrated in the simple steps below.


Step 1

1. Get IronPDF

First, install IronPDF to your Visual Studio project. Get it in whichever way is easier for you, either from DLL download or on the NuGet website. Access the C# Library in Visual Studio and let's add a signature.

# Product Installation using NuGet
nuget install IronPdf
# Product Installation using NuGet
nuget install IronPdf
SHELL

How to Tutorial

2. Understanding Digital Signatures

A Digital Signature is like an electronic driver's license or passport that proves your identity. A digital ID typically contains your name and email address, the name of the organization that issued it, a serial number, and an expiration date. Digital IDs are used for certificate security and digital signatures. This will need to be created with Adobe Acrobat for it to work.


3. Digitally Sign a PDF

Now, let's see the steps for creating an x509certificate2 to digitally sign a PDF using C#.

Today, the IronPDF library offers a simple way to apply signatures, saving time and effort with just a single line of code. You can use it for free during development to test your work. Then, decide on your project. Will you be creating a new document or signing an existing PDF?

In the code example below, a C# form is used to allow the user to select their desired PDF, which can receive a digital signature with a single click.

A .pfx file (Personal Information Exchange Format) should be prepared, which is used to transfer a certificate with the help of a private key.

The SignPdfFile(FileName) method from the PdfSignature class is the main method for a digital signature. Simply select the desired file.

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

The above C# code represents a Windows Form application, where:

  • A button is used to open a file dialog for selecting a PDF file.
  • A second button triggers the signing of the selected PDF using a predefined `.pfx` file and password.
  • Labels are updated to confirm the completion of the signing process.

4. Review Document Signature

As you can see in the output below, as long as a PDF file is selected and the Import Signature button is clicked, it successfully digitally signs the document. With IronPDF, it only took a single line of code.

x509certificate2 Add Digital Signature to PDF Programmatically, Figure 1:


x509certificate2 Add Digital Signature to PDF Programmatically, Figure 2:


IronPDF is the perfect tool for PDF-related tasks using C#. IronPDF offers developers methods to render PDF documents into images and extract text and content from a PDF. Additionally, IronPDF is capable of rendering charts in PDFs, adding barcodes using the IronBarcode library, enhancing security with passwords, watermarking, and even handling PDF forms programmatically.


Library Quick Access

Documentation related to Library Quick Access

API Reference

Read the IronPDF documentation and full list of functions.

API Reference

Häufig gestellte Fragen

Wie kann ich einer PDF-Datei programmatisch in C# eine digitale Signatur hinzufügen?

Um einer PDF-Datei in C# eine digitale Signatur hinzuzufügen, verwenden Sie IronPDF. Installieren Sie zuerst IronPDF über NuGet oder laden Sie die DLL herunter. Verwenden Sie dann die `x509certificate2`-Klasse, um das Zertifikat zu verwalten, und die `PdfSignature`-Klasse, um die Signatur mit einer `.pfx`-Datei und einem Passwort mithilfe der `SignPdfFile`-Methode anzuwenden.

Welche Bedeutung hat eine digitale Signatur in PDFs?

Digitale Signaturen in PDFs bieten einen zusätzlichen Schutz, indem sie die Identität des Absenders überprüfen, ähnlich einem elektronischen Reisepass. Sie gewährleisten die Authentizität und Integrität des Dokuments und verhindern unbefugte Änderungen.

Ist es einfach, ein PDF mit IronPDF zu signieren?

Ja, das Signieren eines PDF mit IronPDF ist einfach. Es erfordert nur eine einzige Codezeile mit der `SignPdfFile`-Methode und macht es leicht, digitale Signaturen in Ihre PDF-Dateien zu integrieren.

Welche Rolle spielt die `x509certificate2`-Klasse bei digitalen Signaturen?

Die `x509certificate2`-Klasse in C# wird verwendet, um X.509-Zertifikate zu verwalten und zu handhaben, die für die Anwendung digitaler Signaturen entscheidend sind. Sie liefert Informationen über das Zertifikat und wird zusammen mit IronPDF verwendet, um PDFs zu signieren.

Kann ich IronPDF kostenlos ausprobieren, bevor ich es kaufe?

Ja, IronPDF kann während der Entwicklung kostenlos verwendet werden, um seine Funktionen, einschließlich des digitalen Signierens, zu testen, bevor Sie eine Kaufentscheidung treffen.

Welches Dateiformat sollte ich verwenden, um ein Zertifikat mit einem privaten Schlüssel zum digitalen Signieren zu übertragen?

Verwenden Sie für die Übertragung eines Zertifikats mit einem privaten Schlüssel das `.pfx`-Dateiformat, das als Personal Information Exchange Format bekannt ist.

Wie installiere ich IronPDF in meinem Visual Studio-Projekt?

Installieren Sie IronPDF in Ihrem Visual Studio-Projekt, indem Sie die DLL direkt herunterladen oder NuGet mit dem Befehl `nuget install IronPdf` verwenden.

Welchen Zweck hat die `SignPdfFile`-Methode?

Die `SignPdfFile`-Methode in IronPDF wird verwendet, um eine PDF-Datei mit einem angegebenen Zertifikat und privaten Schlüssel digital zu signieren, und verbessert damit die Sicherheit des Dokuments.

Unterstützt IronPDF .NET 10 vollständig beim Hinzufügen digitaler Signaturen?

Ja. IronPDF ist vollständig kompatibel mit .NET 10, und alle Funktionen für digitale Signaturen – einschließlich der Methoden `PdfSignature`, `x509certificate2`, `Sign` und `SignPdfFile` – funktionieren ohne zusätzliche Konfiguration. IronPDF unterstützt .NET 10 neben vielen anderen .NET-Versionen (z. B. .NET 9, 8, 7 usw.).

Gibt es Voraussetzungen oder .NET-Versionsanforderungen für die Nutzung der digitalen Signaturfunktionen von IronPDF?

Die Funktionen für digitale Signaturen von IronPDF erfordern .NET Version 5 oder höher – einschließlich .NET 10, .NET 9, .NET Core und .NET Standard. Bei älteren Frameworks oder nicht unterstützten Versionen bietet die Bibliothek möglicherweise keine vollständige Kompatibilität oder erfordert zusätzliche Abhängigkeiten.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen