# E-Sign: Validating Signature Hashes Generated from Vector Data in ASP.NET Core C#

> Storing the raw data of the signature, including point positions, velocity, and acceleration, can help strengthen the evidence. By generating and storing a hash of the raw signature data in the encrypted and digitally signed document and in a database, signed documents can be compared and validated.

- **Author:** Bjoern Meyer
- **Published:** 2023-10-30
- **Modified:** 2025-11-16
- **Description:** Storing the raw data of the signature, including point positions, velocity, and acceleration, can help strengthen the evidence. By generating and storing a hash of the raw signature data in the encrypted and digitally signed document and in a database, signed documents can be compared and validated.
- **5 min read** (912 words)
- **Tags:**
  - ASP.NET
  - PDF
  - Digital Signatures
  - Security
- **Web URL:** https://www.textcontrol.com/blog/2023/10/30/esign-validating-signature-hashes-generated-from-vector-data-in-aspnet-core-csharp/
- **LLMs URL:** https://www.textcontrol.com/blog/2023/10/30/esign-validating-signature-hashes-generated-from-vector-data-in-aspnet-core-csharp/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2023/10/30/esign-validating-signature-hashes-generated-from-vector-data-in-aspnet-core-csharp/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TXTextControl.MVC.Core.Viewer.SignatureHash

---

In addition to encrypting and digitally signing a PDF with an electronic certificate, storing the raw data of the signature, including point positions, velocity, and acceleration, can help strengthen the evidence. By generating and storing a hash of the raw signature data in the encrypted and digitally signed document and in a database, signed documents can be compared and validated.

Since version 32.0.2 of the Document Viewer, the *SignatureData* object contains the raw signature data. The *SignaturePoint* class stores the location of each captured signature point and a time stamp.

> **Learn More**
> 
> During the e-signing process, the document is encrypted and digitally signed and is therefore tamper-proof. Additional features, such as storing the raw signature data, including point positions, velocity, and acceleration, can enhance the evidence.
> 
> [E-Sign: Retrieving Timestamped Raw Signature Data ](https://www.textcontrol.com/blog/2023/10/19/retrieving-timestamped-raw-signature-data/llms-full.txt)

### Signature Acquisition

This example shows how to extract the signature lines from the returned signature data and store a hash of it as an attachment to the created PDF document.

![Signature Hash](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/30/a/assets/signature_hash1.webp "Signature Hash")

The first step is to use the Document Viewer to capture a signature, which is then used to sign the document. To do this, click the *Sign New Document* button.

![Signature Hash](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/30/a/assets/signature_hash2.webp "Signature Hash")

### Generating the Hash

The *ProcessSignature* method creates the hash from the signature data. This data is then stored in a local json database file.

```
[HttpPost]
public IActionResult ProcessSignature([FromBody] TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData data)
{
    if (data == null)
    {
        return BadRequest();
    }

    string signatureDataJson = JsonConvert.SerializeObject(data.SignatureLines);
    string hash = CreateHash(signatureDataJson);

    Envelope envelope = new Envelope
    {
        DocumentId = data.UniqueId,
        SignatureHash = hash,
        SignatureData = signatureDataJson
    };

    AddEnvelope(envelope);

    if (SaveSignedPDF(data, envelope))
    {
        return Ok(true);
    }
    else
    {
        return StatusCode(500);
    }
}
```

The *CreateHash* method is the calculation of a SHA256 hash of the signature lines that have previously been serialized as JSON.

```
private string CreateHash(string json)
{
    using (SHA256 sha256Hash = SHA256.Create())
    {
        byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(json));
        return BitConverter.ToString(bytes).Replace("-", "").ToLower();
    }
}
```

### Embedding Attachment

The *SaveSignedPDF* method creates an EmbeddedFile object that contains the hash of the signature lines along with the unique document ID and the actual signature data. The actual signature lines are not necessarily needed, but demonstrate the possibility in case the hash needs to be regenerated. Finally, a digital signature is applied and the embedded file is attached to the PDF document.

```
private bool SaveSignedPDF(TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData data, Envelope envelope)
{
    try
    {
        using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
        {
            tx.Create();
            tx.Load(Convert.FromBase64String(data.SignedDocument.Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat);

            var embeddedFile = new EmbeddedFile($"tx-hash_{data.UniqueId}.txt", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(envelope)), null)
            {
                Relationship = "Data",
                MIMEType = "application/json"
            };

            X509Certificate2 cert = new X509Certificate2("App_Data/textcontrolself.pfx", "123");

            var saveSettings = new TXTextControl.SaveSettings
            {
                EmbeddedFiles = new EmbeddedFile[] { embeddedFile },
                CreatorApplication = "TX Text Control Sample Application",
                SignatureFields = new DigitalSignature[]
                {
                    new TXTextControl.DigitalSignature(cert, null, "txsign")
                }
            };

            var savePath = Path.Combine("App_Data/signed", $"{data.UniqueId}.pdf");
            Directory.CreateDirectory(Path.GetDirectoryName(savePath));
            tx.Save(savePath, TXTextControl.StreamType.AdobePDF, saveSettings);
        }
        return true;
    }
    catch (Exception)
    {
        return false;
    }
}
```

After the document is signed, it is listed in the summary table.

![Signature Hash](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/30/a/assets/signature_hash3.webp "Signature Hash")

Now click on the *Download* button to download the PDF document that was generated. You can see the attached text file in the *Attachments* tab when you open it in Acrobat Reader.

![Signature Hash](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/30/a/assets/pdf.webp "Signature Hash")

If you open the attachment in a text editor, you will be able to see the json structure, including the hash value that was generated.

```
{
  "DocumentId":"5df83af0-f456-4485-a29f-6290c523067b",
  "SignatureHash":"7592d7e308a1aa3cf2c26f7226c572fc1c744a223a0c6eed0431312d807d23c0",
  "SignatureData":"[[{\"X\":190.0,\"Y\":29.28125,\"CreationTimeStamp\":1698671635701},...]]"
}
```

Then click the *Choose File* button and select the file you downloaded. Confirm by clicking *Validate Signature Hash*. You should see the following page if the signature hash comparison was successful and the stored hashes match.

![Signature Hash](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/30/a/assets/signature_hash4.webp "Signature Hash")

### Extracting the Hash

The *Validate* method extracts the hash information from the PDF and compares the stored hash values from the document and the local database file.

```
public IActionResult Validate([FromForm] IFormFile file)
{
    if (file == null)
    {
        return NotFound();
    }

    byte[] bPDF = GetBytesFromFormFile(file);
    var uploadedEnvelope = ExtractEnvelopeFromPDF(bPDF);

    if (uploadedEnvelope == null)
    {
        return NotFound();
    }

    var envelopes = LoadEnvelopesFromJson();
    var envelope = envelopes.FirstOrDefault(e => e.DocumentId == uploadedEnvelope.DocumentId);

    if (envelope != null && envelope.SignatureHash == uploadedEnvelope.SignatureHash)
    {
        return View(true);
    }

    return View(false);
}
```

The *ExtractEnvelopeFromPDF* method uses the ServerTextControl class to load the PDF document and extract the attachment from the EmbeddedFiles property.

```
private Envelope ExtractEnvelopeFromPDF(byte[] document)
{
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
    {
        tx.Create();

        var loadSettings = new TXTextControl.LoadSettings
        {
            EmbeddedFiles = new EmbeddedFile[] { },
        };

        tx.Load(document, TXTextControl.BinaryStreamType.AdobePDF, loadSettings);

        var embeddedFile = loadSettings.EmbeddedFiles
            .FirstOrDefault(ef => ef.FileName.StartsWith("tx-hash_"));

        if (embeddedFile != null)
        {
            return JsonConvert.DeserializeObject<Envelope>(Encoding.UTF8.GetString((byte[])embeddedFile.Data));
        }
    }

    return null;
}
```

### Conclusion

The storage and comparison of signature raw data hash values is a powerful feature that can add an extra layer of security and trust to e-signature workflows.

You will be able to test the sample by downloading it from our GitHub repository.

---

## 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

- [Why Digitally Signing your PDFs is the Only Reliable Way to Prevent Tampering](https://www.textcontrol.com/blog/2025/10/30/why-digitally-signing-your-pdfs-is-the-only-reliable-way-to-prevent-tampering/llms.txt)
- [Exporting Password Protected Documents to PDF in .NET C#](https://www.textcontrol.com/blog/2024/10/28/exporting-password-protected-documents-to-pdf-in-net-c-sharp/llms.txt)
- [How to Secure your PDF Documents with ASP.NET Core C#](https://www.textcontrol.com/blog/2023/11/13/how-to-secure-your-pdf-documents-with-aspnet-core-csharp/llms.txt)
- [Programmatically Fill, Flatten, and Export DOCX Form Templates to PDF in C# .NET](https://www.textcontrol.com/blog/2026/04/10/programmatically-fill-flatten-and-export-docx-form-templates-to-pdf-in-csharp-dotnet/llms.txt)
- [Why Structured E-Invoices Still Need Tamper Protection using C# and .NET](https://www.textcontrol.com/blog/2026/03/24/why-structured-e-invoices-still-need-tamper-protection-using-csharp-and-dotnet/llms.txt)
- [Create Fillable PDFs from HTML Forms in C# ASP.NET Core Using a WYSIWYG Template](https://www.textcontrol.com/blog/2026/03/17/create-fillable-pdfs-from-html-forms-in-csharp-aspnet-core-using-a-wysiwyg-template/llms.txt)
- [Why HTML to PDF Conversion is Often the Wrong Choice for Business Documents in C# .NET](https://www.textcontrol.com/blog/2026/03/13/why-html-to-pdf-conversion-is-often-the-wrong-choice-for-business-documents-in-csharp-dot-net/llms.txt)
- [A Complete Guide to Converting Markdown to PDF in .NET C#](https://www.textcontrol.com/blog/2026/01/07/a-complete-guide-to-converting-markdown-to-pdf-in-dotnet-csharp/llms.txt)
- [Why PDF Creation Belongs at the End of the Business Process](https://www.textcontrol.com/blog/2026/01/02/why-pdf-creation-belongs-at-the-end-of-the-business-process/llms.txt)
- [Designing the Perfect PDF Form with TX Text Control in .NET C#](https://www.textcontrol.com/blog/2025/12/16/designing-the-perfect-pdf-form-with-tx-text-control-in-dotnet-csharp/llms.txt)
- [Why Defining MIME Types for PDF/A Attachments Is Essential](https://www.textcontrol.com/blog/2025/12/10/why-defining-mime-types-for-pdfa-attachments-is-essential/llms.txt)
- [Validate Digital Signatures and the Integrity of PDF Documents in C# .NET](https://www.textcontrol.com/blog/2025/11/14/validate-digital-signatures-and-the-integrity-of-pdf-documents-in-csharp-dotnet/llms.txt)
- [Validate PDF/UA Documents and Verify Electronic Signatures in C# .NET](https://www.textcontrol.com/blog/2025/11/13/validate-pdf-ua-documents-and-verify-electronic-signatures-in-csharp-dotnet/llms.txt)
- [How To Choose the Right C# PDF Generation Library: Developer Checklist](https://www.textcontrol.com/blog/2025/11/12/how-to-choose-the-right-csharp-pdf-generation-library-developer-checklist/llms.txt)
- [Automating PDF/UA Accessibility with AI: Describing DOCX Documents Using TX Text Control and LLMs](https://www.textcontrol.com/blog/2025/10/16/automating-pdf-ua-accessibility-with-ai-describing-docx-documents-using-tx-text-control-and-llms/llms.txt)
- [Converting Office Open XML (DOCX) to PDF in Java](https://www.textcontrol.com/blog/2025/10/14/converting-office-open-xml-docx-to-pdf-in-java/llms.txt)
- [Document SDK Comparison: Complete Document Processing vs. PDF SDK](https://www.textcontrol.com/blog/2025/10/10/document-sdk-comparison-complete-document-processing-vs-pdf-sdk/llms.txt)
- [Extending DS Server with Custom Digital Signature APIs](https://www.textcontrol.com/blog/2025/10/09/extending-ds-server-with-custom-digital-signature-apis/llms.txt)
- [Why PDF/UA and PDF/A-3a Matter: Accessibility, Archiving, and Legal Compliance](https://www.textcontrol.com/blog/2025/10/07/why-pdf-ua-and-pdf-a-3a-matter-accessibility-archiving-and-legal-compliance/llms.txt)
- [Convert Markdown to PDF in a Console Application on Linux and Windows](https://www.textcontrol.com/blog/2025/09/23/convert-markdown-to-pdf-in-a-console-application-on-linux-and-windows/llms.txt)
- [Mining PDFs with Regex in C#: Practical Patterns, Tips, and Ideas](https://www.textcontrol.com/blog/2025/08/12/mining-pdfs-with-regex-in-csharp-practical-patterns-tips-and-ideas/llms.txt)
- [PDF Conversion in .NET: Convert DOCX, HTML and more with C#](https://www.textcontrol.com/blog/2025/08/05/pdf-conversion-in-dotnet-convert-docx-html-and-more-with-csharp/llms.txt)
- [Streamline Data Collection with Embedded Forms in C# .NET](https://www.textcontrol.com/blog/2025/08/02/streamline-data-collection-with-embedded-forms-in-csharp-dotnet/llms.txt)
- [Adding QR Codes to PDF Documents in C# .NET](https://www.textcontrol.com/blog/2025/07/15/adding-qr-codes-to-pdf-documents-in-csharp-dotnet/llms.txt)
- [Adding SVG Graphics to PDF Documents in C# .NET](https://www.textcontrol.com/blog/2025/07/08/adding-svg-graphics-to-pdf-documents-in-csharp-dotnet/llms.txt)
