# Sign PDF Documents with an X.509 Certificate on a Hardware Device

> TX Text Control can be used to retrieve certificates from a hardware device (such as the Windows certificate store, smart cards and PIV cards, USB tokens). This article shows how to use an X.509 certificate stored on a Windows machine in the Windows certificate store.

- **Author:** Bjoern Meyer
- **Published:** 2023-06-05
- **Modified:** 2025-11-16
- **Description:** TX Text Control can be used to retrieve certificates from a hardware device (such as the Windows certificate store, smart cards and PIV cards, USB tokens). This article shows how to use an X.509 certificate stored on a Windows machine in the Windows certificate store.
- **3 min read** (473 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - Digital Signature
  - X509
- **Web URL:** https://www.textcontrol.com/blog/2023/06/05/sign-pdf-documents-with-an-x509-certificate-on-a-hardware-device/
- **LLMs URL:** https://www.textcontrol.com/blog/2023/06/05/sign-pdf-documents-with-an-x509-certificate-on-a-hardware-device/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2023/06/05/sign-pdf-documents-with-an-x509-certificate-on-a-hardware-device/llms-full.txt

---

TX Text Control can digitally sign Adobe PDF and PDF/A documents with X.509 certificates. An X.509 certificate is a digital certificate that implements the widely accepted X.509 Public Key Infrastructure (PKI) standard that verifies that a specific public key belongs to a user, computer, or service identity contained in the certificate. The certificate can be assigned in the SaveSettings class when the document is saved.

### Document Signing Methods

There are two approaches to signing PDF documents with TX Text Control:

- Sign the whole document with a digital certificate
- Sign individual signature fields with a digital certificate(s)

In both approaches, signatures can be created with PFX, DER Cer, or Base64 CER certificate files, loaded from raw data, or selected from the local certificate store.

### Windows Certificate Store

The following method opens a dialog box that allows the user to select the desired certificate from the local Windows certificate store. The selected certificate is returned and can be used to sign the document or the signature fields in a PDF document.

The [X509Certificate2UI](https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2ui?view=net-5.0) class provides a user interface for selecting and viewing X.509 certificates. The following code uses the [SelectFromCollection](https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2ui.selectfromcollection?view=net-5.0) method to open a certificate selection dialog. All registered certificates, including smart cards, are listed in the dialog.

```
static X509Certificate2 RetrieveCertificate() {
         
   // get and open certificate store for current user
   X509Store store = new X509Store(StoreLocation.CurrentUser);
   store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

   // retrieve the certificate using the integrated Windows UI
   X509Certificate2Collection selectedCertificates =
           X509Certificate2UI.SelectFromCollection(
              store.Certificates, 
              "Choose your certificate",
              "Please select a certificate that is used to sign the PDF.",
              X509SelectionFlag.SingleSelection);

   // return the first selected certificate with a private key
   foreach (var certificate in selectedCertificates) {
      if (certificate.HasPrivateKey)
         return certificate;
   }

   return null;
}
```

### Signing the PDF

The *CreateEncryptedPDF* method takes the selected certificate and a document in the internal TX Text Control format and creates a PDF document signed with the given certificate.

```
public byte[] CreateEncryptedPDF(byte[] document, X509Certificate2 certificate) {
   byte[] bPDF;

   using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
      tx.Create();
      tx.Load(document, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

      // apply the first selected certificate
      TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
         DigitalSignature = new TXTextControl.DigitalSignature(certificate, null)
      };

      // save the document as PDF
      tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings);
   }

   return bPDF;
}
```

The following code shows how to call this method with the certificate returned from the certificate store.

```
CreateEncryptedPDF(document, RetrieveCertificate());
```

The dialog box for selecting the certificate from the local Windows certificate store is shown in the following screenshot.

![Windows certificate store](https://s1-www.textcontrol.com/assets/dist/blog/2023/06/05/a/assets/store.webp "Windows certificate store")

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [WeAreDevelopers World Congress Europe 2026 Wrap Up: Record Breaking Days in Berlin](https://www.textcontrol.com/blog/2026/07/13/wearedevelopers-world-congress-europe-2026-wrap-up-record-breaking-days-in-berlin/llms.txt)
- [C# Document Generation: A Developer's Guide for .NET](https://www.textcontrol.com/blog/2026/07/08/csharp-document-generation-developer-guide-for-dotnet/llms.txt)
- [Validating PDF/UA Documents in .NET C#: A Practical Guide](https://www.textcontrol.com/blog/2026/07/06/validating-pdf-ua-documents-in-dotnet-csharp/llms.txt)
- [See Text Control at WeAreDevelopers World Congress Europe 2026 in Berlin](https://www.textcontrol.com/blog/2026/07/06/see-text-control-at-wearedevelopers-world-congress-europe-2026-in-berlin/llms.txt)
- [DWX 2026 Wrap-Up: Four Days of Innovation, Conversations, and Enterprise Document Solutions](https://www.textcontrol.com/blog/2026/07/03/dwx-2026-wrap-up-four-days-of-innovation-conversations-and-enterprise-document-solutions/llms.txt)
- [Create SignFabric Envelopes from Mail Merge Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/23/create-signfabric-envelopes-from-mail-merge-templates-using-dotnet-csharp/llms.txt)
- [Convert SSRS RDL Reports to DOCX and TX Text Control Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/22/convert-ssrs-rdl-reports-to-docx-and-tx-text-control-templates-in-dotnet-csharp/llms.txt)
- [Export Document Tables to CSV in .NET C#](https://www.textcontrol.com/blog/2026/06/19/export-document-tables-to-csv-in-dotnet-csharp/llms.txt)
- [Major SignFabric Updates: Stronger Audit Trails, Validation, and Recipient Workflows](https://www.textcontrol.com/blog/2026/06/17/major-signfabric-updates-stronger-audit-trails-validation-and-recipient-workflows/llms.txt)
- [Text Control Expands North American Conference Presence with WeAreDevelopers World Congress North America](https://www.textcontrol.com/blog/2026/06/12/text-control-expands-north-american-conference-presence-with-wearedevelopers-world-congress-north-america/llms.txt)
- [Converting HTML to Markdown in C# .NET](https://www.textcontrol.com/blog/2026/06/11/converting-html-to-markdown-in-csharp-dot-net/llms.txt)
- [Beyond WebSockets: A Glimpse into the Future of Document Editing with WebAssembly](https://www.textcontrol.com/blog/2026/06/10/beyond-websockets-glimpse-future-document-editing-webassembly/llms.txt)
- [Showcasing the Future of Document Processing at Developer World DWX 2026](https://www.textcontrol.com/blog/2026/06/08/showcasing-the-future-of-document-processing-at-dwx-developer-week-2026/llms.txt)
- [PDF Security Explained: Passwords, Permissions, Encryption and Digital Signatures in C# .NET](https://www.textcontrol.com/blog/2026/06/08/pdf-security-explained-passwords-permissions-encryption-and-digital-signatures-in-csharp-dotnet/llms.txt)
- [NDC Copenhagen 2026: Great Days in the Heart of Copenhagen's Developer Community](https://www.textcontrol.com/blog/2026/06/05/ndc-copenhagen-2026-great-days-in-the-heart-of-copenhagens-developer-community/llms.txt)
- [Automatically Mapping TX Text Control Form Fields to JSON Data in .NET C#](https://www.textcontrol.com/blog/2026/06/03/automatically-mapping-tx-text-control-form-fields-to-json-data-in-dotnet-csharp/llms.txt)
- [Getting Started with SignFabric: From Clone to Your First Signature Envelope](https://www.textcontrol.com/blog/2026/06/02/getting-started-with-signfabric-from-clone-to-your-first-signature-envelope/llms.txt)
- [We Never Pause - Join Us at NDC Copenhagen 2026](https://www.textcontrol.com/blog/2026/05/27/we-never-pause-join-us-at-ndc-copenhagen-2026/llms.txt)
- [MD DevDays 2026: Record Attendance, Packed Expo Hall, and Three Great Days in Magdeburg](https://www.textcontrol.com/blog/2026/05/21/md-devdays-2026-record-attendance-packed-expo-hall-and-three-great-days-in-magdeburg/llms.txt)
- [TX Text Control 34.0 SP4 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/05/20/tx-text-control-34-0-sp4-is-now-available/llms.txt)
- [Techorama 2026: Welcome to The Document Forge](https://www.textcontrol.com/blog/2026/05/15/techorama-2026-welcome-to-the-document-forge/llms.txt)
- [Signed CycloneDX SBOMs for CRA Compliance Available for Text Control Products](https://www.textcontrol.com/blog/2026/05/08/signed-cyclonedx-sboms-for-cra-compliance-available-for-text-control-products/llms.txt)
- [Introducing SignFabric: An Open Source, Enterprise-Ready E-Sign Platform Built with TX Text Control](https://www.textcontrol.com/blog/2026/05/06/introducing-signfabric-an-open-source-enterprise-ready-esign-platform-built-with-tx-text-control/llms.txt)
- [TX Text Control vs IronPDF for Enterprise PDF Workflows: Complete Comparison Guide](https://www.textcontrol.com/blog/2026/04/28/tx-text-control-vs-ironpdf-for-enterprise-pdf-workflows-complete-comparison-guide/llms.txt)
- [Building a Modern Track Changes Review Workflow in ASP.NET Core C#](https://www.textcontrol.com/blog/2026/04/28/building-a-modern-track-changes-review-workflow-in-aspnet-core-csharp/llms.txt)
